[URGENT] Trailing stop with price level is wrong!

b129.302
backtest: multicharts





At first I wanted to create a custom trailing price level like this below,



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;   



Attachments
  • Votes +3
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

e
#1

eastpeace

06.09.2020 17:00

Task created

e
#2

eastpeace

06.09.2020 17:04

Attachment Strategy 02790.sqx added

Strategy 02790.sqx
(38.12 KiB)
KL
#3

kainc301

07.09.2020 03:13
Voted for this task.
KL
#4

kainc301

07.09.2020 03:14
Have you had problems using multicharts strategies in the platform from 129.302?
e
#5

eastpeace

07.09.2020 03:39
In most cases it works for Multicharts.


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.

b
#6

beppil

09.09.2020 01:15
Voted for this task.
TB
#7

Tomas Brynda

29.09.2020 15:34

Status changed from New to Fixed

Hi Eastpeace,

you are right, thank you for bringing up this issue.


I have fixed the trailing stop logic in TS code.


Best regards,

Tomas

t
#8

telemanius

07.12.2020 05:38
Voted for this task.

Votes: +3

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please