AmiBroker Library
Place orders from your AmiBroker strategy into one or many accounts, using our ready-made AFL library.
Install our AFL library through the AutoTrader Desktop Client, include it at the top of your strategy, and you can place orders from AmiBroker into one or many accounts. The library ships ready-made sample AFLs for regular, bracket and cover orders, scanners, button trading and multi-account trading.
What it is
The AmiBroker library is an AFL library that lets you place orders from your AmiBroker strategy into single or multiple accounts. It ships ready-made sample AFLs for regular, bracket and cover orders, scanners, button trading and multi-account trading.
How it connects
AmiBroker is a bridge client. Your AFL writes order requests to files on your computer. The Desktop Client, running locally, reads those files and sends the real instructions on to AutoTrader Web and your broker. So you need the Desktop Client installed and running.
Before you begin
Have these ready first:
- The AutoTrader Desktop Client, installed and running in MONITORING state.
- AmiBroker installed on your computer.
- An AutoTrader Web account, with your API key set in the Desktop Client.
- At least one broker account added as a pseudo account.
Demos
All AmiBroker demos are available in this YouTube playlist.
Installation
- Install the AutoTrader Desktop client
- Start the Desktop client
- Go to the Settings tab
- Click the Amibroker Library Install button
- Select the directory where your AmiBroker is installed
- Default path: C:\Program Files\AmiBroker
- Once you select the directory, click “Install Here”
- Wait for about a minute to allow the installation to complete
- You will see a message “Installation completed successfully”
The installation step downloads the AFL library files and copies them to the “Formulas\Include” folder in your AmiBroker installation.
Make sure the IPC directory matches in the AFL library as well as the Desktop client. The only difference is that AmiBroker needs a double backslash (\\) as the separator.
- Look for this entry in “Formulas\Include\autotrader-ipc.afl”:
- IPC_DIR = “C:\\Users\\
\\autotrader”;
- IPC_DIR = “C:\\Users\\
- On the Desktop client, go to the Settings tab:
- Make sure the IPC Path matches the “Communication folder” value
Integration
Once the library is installed, the next step is to integrate it into your trading strategy. This is simple. You can also look at the samples available in the “Formulas\AutoTraderWeb” folder (look at the Charts tab in AmiBroker).

AutoTrader Web Sample AFLs
Warning: Do not modify these files. They are overwritten when you re-install the library. Use them as a reference and copy the code into new AFL files if you need. Make sure your personal AFL files are NOT in the AutoTraderWeb folder.
Code
As with any other library, to use its functions in your strategy code, you must include it at the top of your strategy’s AFL.
#include <autotrader.afl>
That’s all. This AFL internally includes all dependencies. Now you can use the API functions provided in the library.
Regular Order
orderId = placeOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL,
"BUY", "MARKET", AT_PRODUCT_TYPE, AT_QUANTITY,
buyPrice, defaultTriggerPrice(), True);
Bracket Order
orderId = placeBracketOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL,
"BUY", "LIMIT", AT_QUANTITY,
buyPrice, defaultTriggerPrice(), 5, 3, 1, True);
Cover Order
stoplossTriggerPrice = buyPrice - 5;
orderId = placeCoverOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL,
"BUY", "LIMIT", AT_QUANTITY,
buyPrice, stoplossTriggerPrice, True);
Cancel Order
orderId = placeOrder(AT_ACCOUNT, AT_EXCHANGE, AT_SYMBOL,
"BUY", "MARKET", AT_PRODUCT_TYPE, AT_QUANTITY,
buyPrice, defaultTriggerPrice(), True);
// You can save this orderId in a static variable
saveStaticVariableText(AT_ACCOUNT, "ORDER_ID", orderId);
// Somewhere later in your code,
// when you want to cancel this order
// Read orderId from static variable
orderId = readStaticVariableText(AT_ACCOUNT, "ORDER_ID");
// Cancel the order
cancelOrder(AT_ACCOUNT, orderId);
API Functions
All API functions are available inside “Formulas\Include\autotrader-api.afl”. Do NOT modify this AFL file.
Note: A detailed explanation is provided for each function along with examples in the API documentation.
Parameters
The AFL library defines certain parameters that you can set in the chart/exploration parameters window. They are listed below.
| Parameter | Meaning |
|---|---|
| AT_ACCOUNT | Pseudo account |
| AT_EXCHANGE | Instrument’s exchange |
| AT_SYMBOL | Instrument’s symbol |
| AT_PRODUCT_TYPE | Default product type |
| AT_QUANTITY | Default quantity |
| AT_PRICE_PRECISION | Price precision for rounding |
| AT_DEBUG | Print additional logs |
| AT_AVOID_REPEAT_ORDER_DELAY | Avoid repeat order delay (in seconds) |
A broker independent instrument’s Exchange & Symbol can be looked up using this global instruments search tool.

AmiBroker Chart Parameters

Amibroker Chart Parameters – Derivatives
Sample Strategies
Sample strategies are available under “Formulas\AutoTraderWeb”.
Button Trading
Many sample button trading AFLs are available under “Formulas\AutoTraderWeb\Buttons”. We recommend you read and understand the AFL code before using them.
A detailed guide on button trading is available on AmiBroker Multi-Account Button Trading.
Scanner
The most important thing to remember is to use the Name() function to get the scanner symbol. Do not use the AT_SYMBOL parameter defined by our library.
You can map your datafeed provider’s symbol to AutoTrader Web’s symbol using a CSV file. You can also trade a different quantity per scanner symbol by mapping the quantity in a CSV file.
Look for the sample AutoTraderWeb\General\at-supertrend-scanner.afl. You can enable CSV files and set the file path in the chart parameters as shown below.

AmiBroker Scanner Parameters
Sample “symbol-mapping.csv”
- Column 1: Datafeed provider symbol
- Column 2: AutoTrader Web’s broker independent symbol
- Give a comma (,) at the end of each line
- See sample entries below, copy them and paste into a CSV file
BANKNIFTY-I,BANKNIFTY_24-SEP-2020_FUT,
BANKNIFTY-II,BANKNIFTY_26-NOV-2020_FUT,
NIFTY-I,NIFTY_24-SEP-2020_FUT,
Sample “quantity-mapping.csv”
- Column 1: Datafeed provider symbol
- Column 2: Quantity for the symbol
- Give a comma (,) at the end of each line
- See sample entries below, copy them and paste into a CSV file
BANKNIFTY-I,50,
BANKNIFTY-II,25,
NIFTY-I,75,
Trading in Multiple Accounts
There are two approaches to trading into multiple accounts. You can read about them in Trading Strategies For Multiple Accounts.
Approach 1: One Strategy Instance Per Account
To trade in multiple accounts in AmiBroker, run multiple charts or scanners, with one chart/scanner per account.
Approach 2: One Strategy for All Accounts
A single strategy runs across multiple accounts. We have already provided multi-account trading sample AFLs in our library. See the screenshots below.

Multi-account trading AFLs

Set multiple account names in chart parameters
Place Order on Next Candle or Bar
This feature handles a specific scenario. Sometimes you will see short lived signals. A short lived signal is one that appears on a bar or candle and disappears by the time the bar or candle is complete.
You can avoid this problem by placing the order on the Next Bar or Candle. We have added this feature in our sample AFLs, and you can set it to ON if you need it. See the screenshot below.

Place order on next Bar or Candle
Debug
A simple way to debug AFL code is to use the _TRACE() function and observe the TRACE logs. First, set up your AmiBroker to view logs.
- Increase _TRACE() output to max (5000 lines) (see screenshot below)
- Bring up the log window (AmiBroker Menu: Window -> Log)
- Go to the Trace tab and enable both Internal & External output (see screenshot below)
- Enable the switch to print additional logs in the parameters window (see screenshot below)

Trace output max lines

Trace enable internal and external output

Print additional logs parameter
Logging
Logging helps you understand how your strategy works during live market hours. It also helps when investigating issues. It is similar to the _TRACE function above, but has more advantages: there is no limit on the file length, and the logs are kept even after AmiBroker is closed.
You can configure file based logging in the chart parameters.

AmiBroker Logging Library Parameters
Additional Information
You can find solutions to common issues in the knowledgebase.
Also be aware of this AmiBroker issue. Make sure you use the RequestTimedRefresh() function as shown in the samples provided.
Compatibility with AmiBroker version 5.7 or below
If you are using version 5.7 or below, we recommend upgrading to 5.8 or above. If that is not possible, then do the following.
- Remove the version check from the file-util.afl file in your AmiBroker’s Include folder.
- The fopen function used in that file uses a flag called shared, which is only present from AmiBroker 5.8 onwards. You need to remove the shared flag.
- Note that you need to do the above steps every time you re-install the AmiBroker library, as reinstalling replaces old files with the latest ones.
Next steps
Thanks for the feedback. Still stuck? Contact support.
Last updated 1 July 2026