- Joined
- 15 February 2012
- Posts
- 51
- Reactions
- 0
In analysis you set the from-to-date on the from screen. Is there a way to embed this within the AFL?
e.g
SetOption(RangeFromDate = 01/12/2014);
SetOption(RangeToDate = "31/12/2014");
I've not been able to find away to do this. I have a number of back tests that I am running from differing dates.
By "embed this..." do you mean calling the from-to setting?
If so then see Status() function in AB help and check available status codes. It's there.
If you mean setting from-to via AFL then use a condition (DateNum() range) to be added to Buy/Sell/Short/Cover variables.
Besides you can save your work to project files (.apx). Those project files save your AFL plus all backtest settings.
Filter = EMA( C, FastMALength ) > EMA( C, SlowMALength ) A AND DateNum() >= 1150218 AND DateNum() <= 1150630;
RestorePriceArrays();
Hi,
From what I've read, I thought if I define the BuyPrice, SellPrice, etc. in the code that the backtester would use those arrays (instead of the BT settings). This is not what I am experiencing. Perhaps someone could provide me with the answer to what I am missing.
Thanks!
MaxPositions = 4;
SetOption("MaxOpenPositions", MaxPositions );
SetOption("WorstRankHeld", MaxPositions + 2 );
SetOption("InitialEquity",15000);
SetPositionSize( 100 / MaxPositions, spsPercentOfEquity );
// trade on next day open
BuyPrice = Open;
SetTradeDelays( 1, 1, 1, 1 );
SetBacktestMode( backtestRotational );
Filter = DateNum() >= 1150514 AND DateNum() <= 1150630;
RestorePriceArrays();
PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), 0 );
StaticVarSet( Name() + "Score", 10000 - ROC( C, 252 ) );
SetCustomBacktestProc("");
if ( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject();
bo.backtest( 1 );
// closed trades
for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() )
{ // two additional columns
trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) );
trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) );
}
// open trades
for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() )
{ // two additional columns
trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) );
trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) );
}
bo.listTrades();
}
Can someone see where my problem is with the following code. My problem is running the afl that the actual trade delay is coming from my backtest settings which has a default to buy price at close.
The AFL code in theory sets the trade delay to buy at open the following day.
Code:MaxPositions = 4; SetOption("MaxOpenPositions", MaxPositions ); SetOption("WorstRankHeld", MaxPositions + 2 ); SetOption("InitialEquity",15000); SetPositionSize( 100 / MaxPositions, spsPercentOfEquity ); // trade on next day open BuyPrice = Open; SetTradeDelays( 1, 1, 1, 1 ); SetBacktestMode( backtestRotational ); Filter = DateNum() >= 1150514 AND DateNum() <= 1150630; RestorePriceArrays(); PositionScore = Iif( Filter, 10000 - ROC( C, 252 ), 0 ); StaticVarSet( Name() + "Score", 10000 - ROC( C, 252 ) ); SetCustomBacktestProc(""); if ( Status( "action" ) == actionPortfolio ) { bo = GetBacktesterObject(); bo.backtest( 1 ); // closed trades for ( trade = bo.GetFirstTrade(); trade; trade = bo.GetNextTrade() ) { // two additional columns trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) ); trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) ); } // open trades for ( trade = bo.GetFirstOpenPos(); trade; trade = bo.GetNextOpenPos() ) { // two additional columns trade.addcustomMetric( "Score@entry", Lookup( StaticVarget( trade.symbol + "Score" ), trade.EntryDateTime ) ); trade.addcustomMetric( "Score@exit", Lookup( StaticVarget( trade.symbol + "Score" ), trade.ExitDateTime ) ); } bo.listTrades(); }
When I change the buyprice to open in the parameters it works as I want.
Understood, is there a way to change the default backtest settings?
What do you mean?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?