To import trading data from AmiBroker into BTAnalytics, you can use a Custom Backtest file in order to write the trades and other extended information using the BTAnalytics XML format. For further details, please see: Importing Text Files With Extended Information in XML Format in the BTAnalytics Documentation.


We have created the needed Custom Backtest file in order to be used to export data in the desired format. You can use that file as a base and modify it if necessary.


To be able to import data into BTAnalytics from AmiBroker, take the following steps:


1.Download the AmiBroker Data Feeder file from the BTAnalytics website.


You can download the AmiBroker Data Feeder file from the External Data Feeders download page in our website.


2.Unzip the AmiBroker Data Feeder file.


You must decompress the downloaded file and move all the included files to a folder in order to access them from the "Analysis Window" of AmiBroker.


Two files are included in the downloaded package:

o"": Is the Custom Backtest file to be called from your trading systems files.
o"": An example that shows the general structure that a Trading System file must have in order to export data.


You should take a look at least to the "" file in order to familiarize yourself with the exporting procedure.


3.Configure your AmiBroker Trading System.


At the beginning of your Trading System file, you must include the following code:


// *******************************

// [REQUIRED] Enable the BTAnalytics Custom Backtest formula to export the backtest data:


// *******************************


// *******************************

// [REQUIRED] [DO NOT MODIFY] Extended Price Info to include with trades exported to BTAnalytics:

StaticVarSet( "bta_open_"+Name(), Open );

StaticVarSet( "bta_close_"+Name(), Close );

StaticVarSet( "bta_high_"+Name(), High );

StaticVarSet( "bta_low_"+Name(), Low );

StaticVarSet( "bta_volume_"+Name(), Volume );

// *******************************



if (Status("stocknum") == 1)


 // ********************************************************************


 // File and Folder where the exported data must be written:

 StaticVarSetText( "bta_ExportFileName", "example2");

 StaticVarSetText( "bta_ExportPath", "d:\\BTAnalyticsImportFolder\\");


 // ********************************************************************


 // Descriptive Data to Export to BTAnalytics:


 StaticVarSetText( "bta_CurrentFormulaFilePath", "C:\\Program Files (x86)\\AmiBroker\\Formulas\\Systems\\");


 StaticVarSetText( "bta_StudyName", "Example Formula Simulation");

 StaticVarSetText( "bta_TacticName", "Example");

 StaticVarSetText( "bta_DatasetName", "All Symbols");

 StaticVarSetText( "bta_ShortNotes", "AmiBroker Trading Data Import Example");

 StaticVarSetText( "bta_Notes", "This is an example that exports Trading Data from AmiBroker into BTAnalytics.");

 StaticVarSetText( "bta_IgnorePriorityWhenComparingTrades", "true");

 StaticVarSetText( "bta_TacticAuthor", "Domintia Software SRL");

 StaticVarSetText( "bta_TacticDescription", "Example Formula that uses the MACD indicator to generate signals.");

 StaticVarSetText( "bta_PosSizerType", "PercentOfEquity");

 StaticVarSetText( "bta_PosSizerParameter", "10");

 StaticVarSetText( "bta_PosSizerCustomConfig", "");





As you can see, the first thing required is to call the "SetCustomBacktestProc" passing as the first argument the relative path to the "" file.


After that, you should set some static variables that are required in order to access the Open, High, Low, Close and Volume arrays in the Custom Backtest file.


Then, only for the first instrument in the backtest, you must set the export file name and path, and optionally you could also set other informative parameters to be imported along with the Trades into BTAnalytics.


That is all! after the previous code, you should write your Trading System source code just as always. The exported data could be manually imported into BTAnalytics or automatically imported if the files are written into a folder being actively monitored by BTAnalytics.


4. Execute your Trading System (Backtest it).


The files containing the Trading System backtest results will be written into the folder configured in the code (in this example the folder is "d:\BTAnalyticsImportFolder\")



5. Import your Trading System results into BTAnalytics.


Files containing Trading Systems backtest results can be imported into BTAnalytics using two methods:


Method 1: Manually importing files by clicking on the "Import File" button in BTAnalytics and then selecting the desired file.


Method 2: Files are automatically imported into BTAnalytics whenever they are written in a monitored folder without need of user intervention. You can configure the monitored folders in the Import Settings dialog of BTAnalytics.





Exporting Auto Stops Data (Optional).


If your Trading System uses auto stops (Stop Loss, Profit Target or Trailing Stop) and you want this data to be exported to BTAnalytics for further analysis, you should include before your Trading System source code the following or a similar snippet:



// [OPTIONAL] Set The Automatic Stops:

profitTargetPct = 10;

stopLossPct = 10;

trailingStopPct = 11;


// *******************************

// [OPTIONAL] Automatic Stops:

StaticVarSet( "bta_ProfitTargetPct_"+Name(), profitTargetPct );

StaticVarSet( "bta_StopLossPct_"+Name(), stopLossPct );

StaticVarSet( "bta_TrailingStopPercent_"+Name(), trailingStopPct );

// *******************************




That code saves in static variables the profit target, stop loss and trailing stop values (in %), and this data is included along the exported trades.


Inside your Trading System code, you should insert a code similar to the following in order to execute the stops when necessary:











Exporting Analysis Variables (Optional).


For an in depth description of Analysis Variables and their utility, please, see the Adding Analysis Variables Filters Tutorial and Analysis Vars DAV description in the BTAnalytics Documentation.


If you want to include Analysis Variables for further analysis or to design filters over them using the BTAnalytics Analysis Vars DAV or the Analysis Vars Derivation Builder, you have to include code similar to the following before your Trading System code:



// *******************************

// [OPTIONAL] Analysis Variables to export to BTAnalytics for further analysis:

StaticVarSet( "bta_anvar_" + Name() + "::" + "ATR-14", ATR(14) );

StaticVarSet( "bta_anvar_" + Name() + "::" + "RSI-20", RSI(20) );

StaticVarSet( "bta_anvar_" + Name() + "::" + "ADX-20", ADX(20) );

// *******************************




The previous code exports along with each trade the values of the ATR(14), RSI(20) and ADX(20) indicators.



When you imports into BTAnalytics the trading data, you will be able to analyze the results for the Analysis Vars in the Analysis Vars DAV of the Raw Simulation Study or in the Analysis Var Derivation Builder:


Analysis Vars DAV
Analysis Vars DAV



Note: AmiBroker is a trademark of