Save Calcs as Statics for Custom Backtester Use

Topics about the AmiBroker platform
User avatar
Posts: 948
Joined: Thu Jul 26, 2007 7:20 pm

Save Calcs as Statics for Custom Backtester Use

Postby progster » Fri Nov 25, 2011 2:50 pm

Regarding a scenario where a user wanted to have an ATR value available in the custom-backtest phase, but found that it was not ready as of the From Date, TJ writes in the AB Yahoo Group : (bold emphasis mine)

... in the portfolio backtest phase, current symbol is the ~~~EQUITY, and its very first bar is the bar the "From" date.

The symbol you are working with (DIFFERENT than Equity) may and usually will start way earier.

If you use SetForeign/Foreign it always synchronizes data to current equity

- it is described in the User's Guide (see Foreign function docs).

So in portfolio backtester, if you do SetForeign() your original symbol data will start from "FROM" date.
Now if you happen to use ATR in the very first nATRPeriod period bars, the ATR will not be available.

What is the lesson learned?
1. Assume your own errors.
2. If you need some value from the FIRST backtest phase in the custom backtester, use static variables
to store any values you need in the first phase and read them in custom backtester.
It is easier and way way faster to execute.

Code: Select all

StaticVarSet("MyAtr"+Name(), ATR( nATRPeriod ) );

if( Status("action") == actionPortfolio )

   bo = GetBacktesterObject();

   for (trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade())
   strSymbol = trade.Symbol;
   fEntryDateTime = trade.EntryDateTime;
   fATR = Lookup( StaticVarGet("MyAtr"+ strSymbol ), fEntryDateTime);


Return to “AmiBroker Discussion”

Who is online

Users browsing this forum: No registered users and 1 guest