Loads of Trailing Stop codes are linked here …
Snippet Link Library
Would anyone like to share (could be from Library above) a Trailing Stop (TS) Code they have found to be effective (could be Gain increase or Drawdown reduction?) when added to their AutoTrading System(s)?
A TS code that allows different settings when Long or Short should be very interesting?
Thank You
My favorite is still:
//VARIABLES STOP SUIVEUR
ONCE trailingStopType = 1 // Trailing Stop - 0 OFF, 1 ON
ONCE trailingstoplong = 7.5 // Trailing Stop Atr Relative Distance
ONCE trailingstopshort = 4 // Trailing Stop Atr Relative Distance
ONCE atrtrailingperiod = 25 // Atr parameter Value
ONCE minstop = 0 // Minimum Trailing Stop Distance
// TRAILINGSTOP
//----------------------------------------------
atrtrail = AverageTrueRange[atrtrailingperiod]((close/10)*pipsize)/1000
trailingstartl = round(atrtrail*trailingstoplong)
trailingstartS = round(atrtrail*trailingstopshort)
if trailingStopType = 1 THEN
TGL =trailingstartl
TGS=trailingstarts
if not onmarket then
MAXPRICE = 0
MINPRICE = close
PREZZOUSCITA = 0
ENDIF
if longonmarket then
MAXPRICE = MAX(MAXPRICE,close)
if MAXPRICE-tradeprice(1)>=TGL*pointsize then
if MAXPRICE-tradeprice(1)>=MINSTOP then
PREZZOUSCITA = MAXPRICE-TGL*pointsize
ELSE
PREZZOUSCITA = MAXPRICE - MINSTOP*pointsize
ENDIF
ENDIF
ENDIF
if shortonmarket then
MINPRICE = MIN(MINPRICE,close)
if tradeprice(1)-MINPRICE>=TGS*pointsize then
if tradeprice(1)-MINPRICE>=MINSTOP then
PREZZOUSCITA = MINPRICE+TGS*pointsize
ELSE
PREZZOUSCITA = MINPRICE + MINSTOP*pointsize
ENDIF
ENDIF
ENDIF
if onmarket and PREZZOUSCITA>0 then
EXITSHORT AT PREZZOUSCITA STOP
SELL AT PREZZOUSCITA STOP
ENDIF
ENDIF
Whats your favorite GraHal?
I haven’t got a favourite (yet! 🙂 ) … apart from you kindly posting your fav TS, it doesn’t look like others have a favourite either as no more posts since yours.
I have tried TS’s in the past, but most barely improved overall performance and several reduced performance. I guess it depends on the strategy and exit conditions etc.
I have an Algo working on 1 hour TF, Exit is a switch of direction, but after seeing Gain increase then fall back again, I thought .. maybe a TS might help here.
I tried Exit when Close < MA and Close Crosses under MA etc, but that didn’t help much overall either.
I have about 20 versions of the Algo currently on Demo Live test … some without TS, some with various TS’s and some with MA’s etc … I have these working 1 min TF, one is on 1 sec TF (main strategy is on 1 hour TF).
I’ll let you know the outcome.
Thank you JS, forgive the daft question, but what does x represent from your code?
If xLongOnMarket then
JSParticipant
Senior
Hi GraHal,
Sometimes the official instructions/commands of PRT do not work as expected, for example if you use “StrategyProfit” and your system goes directly from “Long” to “Short” or vice versa, then the “StrategyProfit” will not work properly (too late)…
In such cases, I create my own variable by putting an “x” in front of it (xStrategyProfit) so that I know that this is my own variable…
JSParticipant
Senior
In this case, it would be something like this:
If BuyCondition then
Buy 1 contract at Market
xLongOnMarket=1
xShortOnMarket=0
EndIf
If ShortCondition then
SellShort 1 contract at Market
xLongOnMarket=0
xShortOnMarket=1
EndIf