Hello all, I am coding a scale-in template for trading APPL, however, after I executed the codes, the backtest report could not display (it's my problem I understood) properly, and I wonder what I coded wrongly in the template as I used the similar template and was able to scale-OUT in another backtest previously. I tried to debug in explorer but found no logical mistakes currently.
Please see my following codes for reference, thank you.
SetPositionSize(100,spsPercentOfEquity);
SetTradeDelays( 0, 0, 0, 0 );
SetOption( "ActivateStopsImmediately", True );
SetOption( "AllowSameBarExit", False);
SetOption("MaxOpenPositions",10);
Buy = Sell = 0;
MA_indicator = MA(Close,200);
RSI_indicator = RSI(4);
Entered_flag = 0;
// RMB!!! Buy at close
_SECTION_BEGIN( "Controlled TSL" );
for( i = 3; i < BarCount; i++ ) {
Entered_flag[i] = Entered_flag[i-1];
BuyPrice[i] = BuyPrice[i-1];
if (RSI_indicator[i] < 30 AND RSI_indicator[i] > 25 AND Entered_flag[i] != 1 AND Close[i] > MA_indicator[i]) {
Buy[i] = sigScaleIn;
BuyPrice[i] = Close[i] ;
Entered_flag[i] = 1;
}
if (RSI_indicator[i] < 25 AND Entered_flag[i] == 1 ) { //AND Close[i-1] > MA_indicator[i-1]
Buy[i] = 1;
BuyPrice[i] = Close[i] ;
Entered_flag[i] = 1;
}
if (RSI_indicator[i-1] < 55 AND RSI_indicator[i] >= 55 AND Entered_flag[i] == 1) {
Sell[i] = 1;
SellPrice[i] = Close[i] ;
Entered_flag[i] = 0;
}
}
Filter = 1;
AddColumn(MA_indicator,"MA_indicator",1.4);
AddColumn(RSI_indicator,"RSI_indicator",1.4);
AddColumn(Entered_flag,"Entered_Flag",1.4);
AddColumn(Buy,"Buy",1.4);
AddColumn(Sell,"Sell",1.4);
AddColumn(Open,"Open",1.4);
AddColumn(Close,"Close",1.4);
SetPositionSize( 50 , IIf(Buy == sigScaleIn,spsPercentOfPosition,spsNoChange)); // scale in 50% of position