b131 dev2
backtest engine : multicharts
if(MarketPosition > 0) then begin
...
// Trailing Stop
IntPriceLevel = SQ_Highest(WeightedClose, Period)[0] + (0.80 * SQ_BiggestRange(Period2)[2]);
If IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(TrailingActCef * SQ_ATR(20)[1]) and (IntLongTS = 0 or Round2Fraction(IntPriceLevel) > IntLongTS) and Round2Fraction(IntPriceLevel) < CurrentBid then begin
IntLongTS = Round2Fraction(IntPriceLevel); // remember also trailing stop
end;
If IntLongTS > 0 and IntLongTS > IntLongSL then begin
Sell("LongTrailingStop") next bar at IntLongTS stop;
LongSLPlaced = true;
end;
We know here the trailing stop activation is up to Close - EntryPrice >= TrailingActCef * SQ_ATR(20)[1],
But the right way is, Highest price after entry - EntryPice > trailing activation trigger, example in long position
if(MarketPosition < 0) then begin
...
If BarsSinceEntry = 0 then begin
...
HighAfterEntry = Close;
end;
if Close > HighAfterEntry then
HighAfterEntry = Close;
// Trailing Stop
...
If IntPriceLevel > 0 and HighAfterEntry - EntryPrice >= Round2Fraction(TrailingActCef * SQ_ATR(20)[1])
and ... then begin
...
end;