Hi, I’m working through this:
http://www.amibroker.org/userkb/2008/03/16/amibroker-custom-backtester-interface-2/
Periodicity is set to Weekly.
My code, the top 5 lines are mine, the rest is from the kb:
BuyPrice = Open; // set buying price array
SellPrice = Open; // set selling price array
SetTradeDelays( 1, 1, 1, 1 );
Sell = Close > MA(Close,5);
Buy = Close < MA(Close,5);
SetCustomBacktestProc( "" );
if( Status( "action" ) == actionPortfolio )
{
bo = GetBacktesterObject(); // Get backtester object
bo.PreProcess(); // Do pre-processing
for( i = 0; i < BarCount; i++ ) // Loop through all bars
{
for( sig = bo.GetFirstSignal( i ); sig; sig = bo.GetNextSignal( i ) )
{
// Loop through all signals at this bar
if( sig.IsEntry() && sig.IsLong() ) // If this signal is a long entry (ie. buy)
{
evol = Foreign( "~evol_" + sig.Symbol, "V" ); // Get stock's composite volume array
psize = sig.PosSize; // Get position size specified in AFL code
if( psize < 0 ) // If it's negative (a percentage of equity)
psize = ( -psize / 100 ) * bo.Equity; // Convert to dollar value using current equity
scnt = psize / sig.Price; // Calculate number of shares for position size
if( scnt > evol[i] / 10 ) // If number of shares is > 10% of volume EMA
{
scnt = evol[i] / 10; // Limit number of shares to 10% of EMA value
psize = scnt * sig.Price; // Calculate new position size
}
if( psize < 5000 ) // If position size is less than $5,000
psize = 0; // Set to zero so buy signal will be ignored
else
{
if( psize > 50000 ) // If position size is greater than $50,000
psize = 50000; // Limit to $50,000
}
sig.PosSize = psize; // Set modified position size back into object
}
} // End of for loop over signals at this bar
bo.ProcessTradeSignals( i ); // Process trades at this bar
} // End of for loop over bars
bo.PostProcess(); // Do post-processing
}
Issue: The trade list shows entries & exits on mid weeks days. I am expecting Monday only for entry and exit.
What is incorrect in my code?
Regards.