b129.302
backtest: multicharts
median price ± N * ATR;
But I found that all trailing price are base on Close yet,
// long position Trailing Stop IntPriceLevel = {CustomBlock:median of high and low}(High[1] + Low[1] / 2); If IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(0) and (IntLongTS = 0 or Round2Fraction(Close - IntPriceLevel) > IntLongTS) then begin IntLongTS = Round2Fraction(Close - IntPriceLevel); // remember also trailing stop end; If IntLongTS > 0 and IntLongTS > IntLongSL then begin Sell("LongTrailingStop") next bar at IntLongTS stop; LongSLPlaced = true; end;
So I tested the inside indicators,
By the way, the description of Stop/Limit entry blocks may be misleading. because it will not only affect entry orders, but also trailing stop exit.
I choose SAR and SMA in Stop/Limit entry blocks, and BarRange in Stop/Limit Price Ranges. I get something like this,
// long Trailing Stop IntPriceLevel = SQ_SMA(Close, SMAPeriod)[1] + (1.10 * SQ_BarRange[3]); If IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(0) and (IntLongTS = 0 or Round2Fraction(Close - IntPriceLevel) > IntLongTS) then begin IntLongTS = Round2Fraction(Close - IntPriceLevel); // remember also trailing stop end; If IntLongTS > 0 and IntLongTS > IntLongSL then begin Sell("LongTrailingStop") next bar at IntLongTS stop; LongSLPlaced = true; end;
I guess the trailing price level is SQ_SMA(Close, SMAPeriod)[1] + (1.10 * SQ_BarRange[3]), And the IntLongTS is IntPriceLevel, not Close- IntPriceLevel.
close - sma for trailing stop price?! Very very unreasonable.
This is not same with trailing stop using ATR-based value (only base on Close price. But if we cant set the base price as High or low, it will be better.)
//Long Trailing Stop 2nd mode, atr-based value,
IntPriceLevel = EnterRvrAtMrkTrlStpCef * SQ_ATR(75)[1];
If IntPriceLevel > 0 and Close - EntryPrice >= Round2Fraction(0) and (IntLongTS = 0 or Round2Fraction(Close - IntPriceLevel) > IntLongTS) then begin
IntLongTS = Round2Fraction(Close - IntPriceLevel); // remember also trailing stop
end;
If IntLongTS > 0 and IntLongTS > IntLongSL then begin
Sell("LongTrailingStop") next bar at IntLongTS stop;
LongSLPlaced = true;
end;
The two are very different, one is price level actually, and one is price range, or allowable fallback, assuming the benchmark price is Close.
For Price level trailing type, I think this below will be right, But I am not sure. Maybe the dev team have better method.
// long Trailing 3. Stop price level type IntPriceLevel = SQ_SMA(Close, SMAPeriod)[1] + (1.10 * SQ_BarRange[3]); If IntPriceLevel > 0 and Close - IntPriceLevel >= Round2Fraction(0) and (IntLongTS = 0 or IntPriceLevel > IntLongTS) then begin IntLongTS = IntPriceLevel; // remember also trailing stop end; If IntLongTS > 0 and IntLongTS > IntLongSL then begin Sell("LongTrailingStop") next bar at IntLongTS stop; LongSLPlaced = true; end;
But I am still not satisfied with some aspects, such as the initial stop loss with price range and some details of trailing stop loss.
Status changed from New to Fixed
you are right, thank you for bringing up this issue.
I have fixed the trailing stop logic in TS code.
Best regards,
Tomas