Skip to content

AmiBroker

AmiBroker AFL Install Guide: Step by Step for Any Formula

A plain guide to installing any AFL file in AmiBroker, from copying it into the Formulas folder to running your first Exploration, with fixes for the usual errors.

WizeBuySell Desk6 min read

An AFL file is a plain text file with the extension .afl. Installing one in AmiBroker means putting it in the right folder, applying it to a chart and, if the formula supports it, running it as a scan. None of this is difficult, but the menus are not obvious the first time.

This guide works for any AFL, free or paid, ours or someone else's. Menu names are from recent AmiBroker versions; older builds may word them slightly differently. If you get stuck, the errors section near the end covers the usual causes.

What you need before you start

  • AmiBroker installed on a Windows PC, with your own licence.
  • A database with data in it. For intraday signals that means a real-time feed from an authorised data vendor.
  • The .afl file. If the vendor also sent a .dll plugin, that goes in the Plugins folder, not the Formulas folder.

AFL stands for AmiBroker Formula Language. The same file can draw a chart, raise alerts and scan a watchlist, depending on what the author wrote into it.

Step 1: find the Formulas folder

The Formulas folder sits inside the AmiBroker installation folder. On most PCs that is C:\Program Files\AmiBroker\Formulas, or C:\Program Files (x86)\AmiBroker\Formulas for the 32-bit edition.

If you cannot find it, right-click the AmiBroker shortcut on your desktop and choose "Open file location". That opens the installation folder, and Formulas is inside it.

Step 2: copy the AFL file

Inside Formulas you will see folders such as Basic Charts, Indicators and Custom. Your own files usually go in Formulas\Custom. Copy the .afl file there. Windows may ask for administrator permission because the folder is under Program Files; allow it.

Keep the original file name. Some formulas include other files by name, and renaming breaks the link.

Step 3: find it in the Charts pane

Open AmiBroker and look for the Charts pane, normally docked on the left or right beside Symbols. If it is hidden, switch it on from the Window menu. Expand the Custom folder and your formula should be listed.

If it is not there, right-click inside the Charts pane and choose Refresh. AmiBroker reads the folder when it starts, so a file copied while the program is open needs a refresh.

Our own AmiBroker version of WizeBuySell is installed through exactly these steps, so everything here applies to it as well.

Step 4: apply the formula to a chart

You have three ways, and they behave differently.

ActionWhat it does
Double-click, or right-click and InsertOpens the formula in a new pane. AmiBroker makes its own copy of the file, so later changes to the original do not reach this chart.
Right-click and Insert LinkedOpens it in a new pane, linked to the original file. Replace the file with an update and the chart updates too.
Drag onto an existing paneOverlays the formula on that pane, on top of what is already there.

For a formula that the vendor will update, Insert Linked is usually the better choice. For a full price-and-signal formula, use a new pane rather than dragging it onto the default price chart, or you will see two sets of candles.

To remove a formula pane, right-click it and choose Close. To remove an overlay from a pane, right-click and use Delete Indicator.

Step 5: set the parameters

Right-click the chart and choose Parameters. The shortcut is Ctrl+R. Any setting the author has exposed appears here: periods, colours, alert switches, and so on. The Axes and Grid tab controls the look of the pane.

Change one thing at a time and note the defaults before you start. A Reset all button brings them back. Parameters are saved per chart pane, so a second chart needs its own settings.

Step 6: run an Exploration

An Exploration runs the formula across many symbols and lists the ones that meet its condition. It only works if the AFL contains a Filter line and at least one AddColumn. Our glossary has more on the Exploration scanner.

  1. Go to Analysis, then New Analysis.
  2. Click the folder icon (Pick a file) and select your .afl.
  3. Set Apply to. Choose All symbols, Current, or Filter. For a watchlist, choose Filter, click the funnel icon beside it and include your watchlist.
  4. Set Range to 1 recent bar, so you see only signals on the latest candle.
  5. Open Settings and check that Periodicity matches the timeframe you trade, for example 15-minute.
  6. Click Explore.

The results appear as a table. Click a column header to sort. Double-click a row to open that symbol's chart.

A tiny example to practise on

Save the snippet below as ema-cross-demo.afl in the Custom folder and walk through steps 3 to 6 with it. It is a plain moving average crossover, written for practice, not for trading.

afl
// Illustrative only - not the WizeBuySell formula
fastEMA = EMA( Close, 9 );
slowEMA = EMA( Close, 21 );

Buy  = Cross( fastEMA, slowEMA );
Sell = Cross( slowEMA, fastEMA );

Plot( Close, "Price", colorDefault, styleCandle );
Plot( fastEMA, "EMA 9", colorGreen, styleLine );
Plot( slowEMA, "EMA 21", colorRed, styleLine );

PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorGreen, 0, Low, -15 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, High, -15 );

// Needed for Exploration
Filter = Buy OR Sell;
AddColumn( Close, "Close", 1.2 );
AddColumn( IIf( Buy, 66, 83 ), "Signal", formatChar );

Buy and Sell are arrays that are true on the crossover candle. PlotShapes draws the arrows. The last three lines make the file usable in an Exploration; the Signal column prints B or S.

Common errors and what they mean

  • Formula not showing in the Charts pane. Right-click and Refresh. If it is still missing, check that the file really ends in .afl and not .afl.txt, which happens when it is saved from Notepad or downloaded from a chat app.
  • "Error 29. Variable used without having been initialized", or a syntax error. The formula itself is broken or incomplete, often because it was copied from a web page and lost some lines. This is not an installation problem. Ask the author for a clean file.
  • Blank chart. Usually there is no data for that symbol, or the timeframe is wrong. Check that your data feed is running. For intraday charts, the database's base time interval must be intraday, such as 1-minute; an end-of-day database cannot show 5-minute candles.
  • Exploration returns nothing. Either no symbol met the condition on the last bar, or the formula has no Filter line. Try a longer Range to confirm.
  • Licence-locked AFL shows a message or plots nothing. Paid formulas are often tied to your PC or AmiBroker user name. Only the vendor can activate them. Reinstalling will not help.

How WizeBuySell does this for you

You do not have to do any of the above for our software. We install it on a remote session over AnyDesk, which takes about 20 minutes. We copy the AFL, apply it to a chart, set your popup and sound alert preferences, set up the watchlist scanner, and check that signals plot on Nifty and one MCX symbol before we disconnect.

You need AmiBroker with your own licence and a real-time feed from an authorised vendor. If you do not have a feed yet, we help you choose one during the trial. If you change your PC later, Yearly and Lifetime plans include reinstallation.

What to do next

This guide is educational and is not investment advice; an AFL plots levels, and the trading decisions are yours. Please read our disclaimer.

If you would rather see a finished setup than build one, book the 2-day free trial. No card is asked for. We install the AFL on your AmiBroker and you get two market days of live signals with entry, three targets and a stop-loss on your own charts.

More from the blog