

* Now custom-backtest procedure follows */ VarSet( varname, Nz( VarGet( varname ) ) + profit ) HINT: you may replace it with GetPercentProfit if you wish If( ! StrFind( tradedSymbols, "," + symbol + "," ) ) This can help to determine on which securities the trading system works well, and on which securities it doesn’t. This AFL will calculate Profit/Loss % for each individual scrip in Portfolio Backtesting. } Amibroker Custom Backtester Examples Example 1: Profit/Loss percentage for individual symbols in portfolio backtest So all custom backtest procedures, where they’re in the same file as the other AFL code, will have a template like this: That’s achieved with the followingĪnd finally, before anything else can be done, a copy of the Backtester object is needed: The next thing that’s required in all backtest procedures is to ensure the procedure only runs during the second phase of the backtest.

This option will be used in the examples going forward in this post. This tells AmiBroker that there is a custom backtest procedure but there’s no path for it, because it’s in the current file.

HOW TO READ BROKDAT4 AMIBROKER FILE CODE
HOW TO READ BROKDAT4 AMIBROKER FILE FULL
– using PreProcess()/EnterTrade()/ExitTrade()/ScaleTrade()/UpdateStats()/HandleStops()/PostProcess() methods – provides full control over entire backtest process for hard-code programmers only – using PreProcess()/ProcessTradeSignal()/PostProcess() methods – allows to modify signals, query open positions (good for advanced position sizing) – using Backtest() method and it runs default backtest procedure (as in old versions) – allows simple implementation of custom metrics The high-level approach requires the least programming knowledge, and the low-level approach the most. The Amibroker custom backtester interface provides three levels of user customization, simply called high-level, mid-level, and low-level. The detailed documentation of these methods can be found here. Image Source: Amibroker Official DocumentationĮach of these objects have multiple methods which can be accesses from within the AFL code. The interface also exposes the signal object, stats object and trade object, but only object directly accessible from AFL is Backtester object, all other objects are accessible by calling Backtester object methods as shown in the picture below. The variable “bo” is your own variable, and you can call it whatever you like within the naming rules of AFL. To use the Backtester object, you first have to get a copy of it and assign that to your own variable: Amibroker provides a single Backtester object to perform backtests. Amibroker Custom Backtester modelĪmibroker uses object oriented model for custom backtesting. You should be ready to write your own custom backtest AFL after reading this post. In this post, we’ll try to explore Amibroker custom backtester features and examples. It allows customizing the operation of the backtester’s second phase which processes the trading signals. Additionally, it also provide custom backtester interface using which you can play around the default backtest rules and metrics. It has a very robust backtest and optimization engine out of the box. Amibroker is one of the most versatile tools for Trading system development and testing.
