I'm having an issue with a strategy I'm backtesting and I need some help troubleshooting. The strategy is placing the entry stop order on a bar I don't want it to, usually several bars after the bar where I want it to be placed. See the attached screenshot for an example.
I've tried troubleshooting by taking out individual conditions, printing indicator values and orders placement history in the output window, and by just walking through all the conditions one by one and comparing them to the backtested trades on the chart. I'm flummoxed.
Here is the code:
// Long trades
if (EMA(BarsArray[1],8)[0] > EMA(BarsArray[1],13)[0]
&& ToTime(Time[0])> ToTime(08,30,00)
&& ToTime(Time[0])< ToTime(14,0,00)
&& High[Math.Min(100000,Swing(SwingStrength).SwingHighBar(SwingBarsAgo,1,SwingBarsBack))] > High[Math.Min(100000,Swing(SwingStrength).SwingHighBar(SwingBarsAgo,2,SwingBarsBack))]
&& Low[Math.Max(0,Swing(SwingStrength).SwingLowBar(SwingBarsAgo,1,SwingBarsBack))] < Low[Math.Max(0,Swing(SwingStrength).SwingLowBar(SwingBarsAgo,2,SwingBarsBack))]
&& Close[1] > (Close[Math.Max(0,Swing(SwingStrength).SwingHighBar(SwingBarsAgo,1,SwingBarsBack))] - Open[Math.Min(100000,Swing(2).SwingHighBar(SwingBarsAgo,1,SwingBarsBack))])*.382 + Open[Math.Min(100000,Swing(SwingStrength).SwingHighBar(SwingBarsAgo,1,SwingBarsBack))]
&& Close[0] >= Open[1]
&& Close[0] >= Close[Math.Max(0,Swing(3).SwingHighBar(SwingBarsAgo,1,SwingBarsBack))] //Optional? Either this OR condition 2
&& (Close[0] - Open[0])/(High[0] - Low[0]) >= 0.6
&& Close[0]-Low[0] >= TickSize*10
)
{
EnterLongStop(DefaultQuantity, Close[0] + 1 * TickSize, "LongEntry1");
SetStopLoss("LongEntry1", CalculationMode.Price, Low[0]-1*TickSize, false);
SetProfitTarget("LongEntry1", CalculationMode.Price, (Close[0]-Low[0])*1.55+Close[0]);
StopMoveTriggerLong = (Close[0]-Low[0])*0.9+Close[0];
}


Comment