At this point, it is not trailing at all. After it makes an initial stop movement after the initial profit target it filled, then it is supposed to trail below the SMA as soon as the SMA is above the price where the stop was initially moved to.
Here is the code:
protected override void OnExecution(IExecution execution)
{
if (LongEntryA != null
&& LongEntryA == execution.Order)
{
// Initial Stop Losses & Profit Target
LongLimit = ExitLongLimit(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongTarget[0],"LongLimit","LongEntryA");
LongStopA = ExitLongStop(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongStop[0],"LongStopA","LongEntryA");
LongStopB = ExitLongStop(TrendPilotPricesLong(EntryPerc, StopPerc, TargetPerc).LongStop[0],"LongStopB","LongEntryB");
}
if (LongLimit != null && LongLimit == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled)
{
ExitLongStop(Position.AvgPrice-(execution.Price - Position.AvgPrice),"LongStopB","LongEntryB");
}
/*After the Entry B stop has made it initial move, we then wait for the SMA to catch up to the price.
When it catches up, then the Stop loss should trail the SMA.
The distance that it trails below the SMA (for longs) will be the ((SignalCandle High) - (Signal Candle Low)*StopPerc).
The Trailing Stop should naturally only go up and never go down in case the SMA begins to turn downward. */
if (SMA(sMAPeriod)[0] - ((signalHigh - signalLow)*StopPerc) > LongStopB.StopPrice)
{
ExitLongStop(SMA(sMAPeriod)[0] - ((signalHigh - signalLow)*StopPerc),"LongStopB","LongEntryB");
}
}
Can you see why it is doing that?

Comment