Hi all, I am trying to implement a CBT for limit entries and to get the limit and low prices for all entry signals on a bar by bar basis in the detailed log. I am using bo.RawTextOutput to get the low prices and limit prices for all entry signals. The issue is that the RawTextOutput is coming on the bar/date before the signal bar. _Trace is working fine and shows the output in the correct bar. The screenshot and code is below, please let me know what I am doing wrong:
BuySignal = AboveMinInc;
Buy = Ref( BuySignal, -1 );
LimitPrice = IIf( Buy, Ref( C, -1 ) * 99/100, 0 ); // below 1% of yesterday's close
BuyPrice = IIf( Buy, Min( O, LimitPrice ), 0 );
// CBT for Limit Entries
SetBacktestMode(backtestRegularRaw);
SetOption("UseCustomBacktestProc", True );
if( Status("action")== actionPortfolio )
{
// retrieve the interface to portfolio backtester
bo = GetBacktesterObject();
bo.PreProcess(); // Do pre-processing (always required)
DetailedLog = GetOption("PortfolioReportMode") == 1;
for (i = 0; i < BarCount; i++) // Loop through all bars
{
PosQty = bo.GetOpenPosQty();
_TRACE("[AB] Day ------ " + i);
_TRACE("[AB] Open Position: " + PosQty);
Count = 0;
for(sig=bo.Getfirstsignal(i) ; sig ; sig=bo.GetNextSignal(i))
{
LowPrice = Foreign( sig.Symbol, "Low" ); //grab the low to check limit order fill
if( sig.IsEntry() )
{
if (DetailedLog)
bo.RawTextOutput("\t " + sig.Symbol + " LowPrice: " + LowPrice[i] + " LimitPrice: " + sig.Price );
_TRACE("[AB] " + sig.Symbol + " LowPrice: " + LowPrice[i] + " LimitPrice: " + sig.price);
if( Count > 2 - PosQty OR LowPrice[i] > sig.price)
sig.Price=-1;
}
Count++;
}
bo.ProcessTradeSignals(i);
}
bo.PostProcess(); // Do post-processing (always required)
}
In the below screenshot the extra lines should come under 3/2/2017 rather than 3/1/2017