The strategy has 2 entries that happen at the same time of which the first entry exits with a small profit using ExitLongLimit. When that ExitLongLimit is triggered and executed then the initial stop loss from the second entry is adjusted to a fixed place. Finally, when the SMA moves above this adjusted stop order, then the trailing stop is supposed to start trailing and be just below the SMA.
According to my Print statements, the code that I have is being called upon, but the stop does not appear to be trailing. I have put in to have it print the trailing stop price in order to see how it moves, but it just gives me one price and then it never gives me any other prices as the trailing stop is supposed to be getting higher.
Here is the code:
if (LongLimit == execution.Order
&& SMA(sMAPeriod)[0] > (TargetPriceLong - LongEntryA.AvgFillPrice))
{
if (Close[0] > SMA(BarsArray[0], sMAPeriod)[0]+((signalHigh-signalLow)*StopPerc))
{
adjustedStopLong = SMA(BarsArray[0], sMAPeriod)[0]-((signalHigh-signalLow)*StopPerc);
LongStopB = ExitLongStop(0,true,positionSize,SMA(BarsArray[0], sMAPeriod)[0] - ((signalHigh-signalLow)*StopPerc),"LongBStop","LongEntryB");
Print(Time[0] + " Trailing Stop = " + adjustedStopLong);
}
}
Could you please help me understand what is happening in this code, and also help me figure out how to get this to properly trail.
Thank you very much for your help!


That usually nips problems like this in the bud, before they rear their ugly heads.
Comment