Trailing stop fails to move

Viewing 15 posts - 16 through 30 (of 30 total)
  • Author
    Posts
  • #148790 quote
    nonetheless
    Participant
    Master

    Actually I’ve got another problem with that TS (as posted above). It moves to breakeven then stops, doesn’t trail with the price movement. Obviously it’s working correctly in backtest, but in live trading it gets stuck. Have you seen this as well?

    #148793 quote
    Paul
    Participant
    Master

    no not yet, it never stops 😉 Your dj 5m mod v5 stopped suddenly with a strange message but I think unrelated to this.

    On the 10s frame I use 2 trailingstops in demo and they seem to work alright, but because of using 2 I don’t know which was triggered. I will check.

    Can you provide a pic?

    Screenshot-2020-10-28-at-15.24.33.jpg Screenshot-2020-10-28-at-15.24.33.jpg
    #148795 quote
    Paul
    Participant
    Master

    those exits were because the atr trialingstop. I will run it without.

    #148796 quote
    nonetheless
    Participant
    Master

    I haven’t got a pic, when I realised it was stuck I closed the position manually. That was with NAS 5m Mod v4S

    #148798 quote
    Paul
    Participant
    Master

    Interested in testing your mod with the atr trailingstop instead to see if it behaves the same live?

    I updated that one, and the breakeven too, both to use cumulative positions, it’s included in de maex strategy

    #148806 quote
    nonetheless
    Participant
    Master

    yeah, I’ll def check it out when I get a minute, it’s either that or go back to the old %TS I had been using. It’s a bit basic but does the job. The big advantage to yours is the separate values for long/short, so maybe I can build that in to the other one (of Nicolas)

    #148809 quote
    Paul
    Participant
    Master

    Thought of another way if you take that trailingstop (it’s all based on the original)

    Duplicate the code and make sure both not overlap each other.

    1st one for long and remove all short code, and the second one for short with all long removed.

    Should be the same effect (besides the accelerator and sensitivity) but still the advantage for separate values.

    josef1604 thanked this post
    #148811 quote
    nonetheless
    Participant
    Master

    My thoughts exactly. Does this look right to you? Seems to test ok

    //%trailing stop function
    trailingpercentlong  = tst // %
    trailingpercentshort = tss // %
    stepPercentlong = st
    stepPercentshort = st2
    if onmarket then
    trailingstartlong = tradeprice(1)*(trailingpercentlong/100) //trailing will start @trailingstart points profit
    trailingstartshort = tradeprice(1)*(trailingpercentshort/100) //trailing will start @trailingstart points profit
    trailingsteplong = tradeprice(1)*(stepPercentlong/100) //% step to move the stoploss
    trailingstepshort = tradeprice(1)*(stepPercentshort/100) //% step to move the stoploss
    endif
    
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND close-tradeprice(1)>=trailingstartlong THEN
    newSL = tradeprice(1)+trailingsteplong
    ENDIF
    //next moves
    IF newSL>0 AND close-newSL>trailingsteplong THEN
    newSL = newSL+trailingsteplong
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-close>=trailingstartshort THEN
    newSL = tradeprice(1)-trailingstepshort
    ENDIF
    //next moves
    IF newSL>0 AND newSL-close>trailingstepshort THEN
    newSL = newSL-trailingstepshort
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF

    Not sure about tradeprice(1), whereas you have positionprice. I know the difference, it’s more the (1) I’m unsure of

    josef1604 thanked this post
    #148814 quote
    Paul
    Participant
    Master

    looks good. Tradeprice as written is correct.  Only the reset is off when reversing a position, but most of the time the difference is smal to nothing.

    nonetheless and josef1604 thanked this post
    #148821 quote
    nonetheless
    Participant
    Master

    Thanks Paul. I added

    sensitivity = (low+high+close)/3

    instead of close and the performance is back to where it was using your TS – at least in backtest it is. Let’s see how it runs live.

    josef1604 thanked this post
    #150172 quote
    nonetheless
    Participant
    Master

    Hi @Paul, I’ve got more problems with this cumulative orders TS. This is the code I’m using:

    // %trailing stop function incl. cumulative positions
    
    once trailingstoptype = 1
     
    if trailingstoptype then
    //====================
    trailingpercentlong  = 0.26 // %
    trailingpercentshort = 0.26 // %
    once acceleratorlong = 0.003 // [1] default; always > 0 (i.e. 0.5-3)
    once acceleratorshort= 0.023 // 1 = default; always > 0 (i.e. 0.5-3)
    ts2sensitivity  = 4 // [1] default [2] hl [3] lh [4] typicalprice (not use once)
    //====================
    once steppercentlong  = (trailingpercentlong/10)*acceleratorlong
    once steppercentshort = (trailingpercentshort/10)*acceleratorshort
    if onmarket then
    trailingstartlong = positionprice*(trailingpercentlong/100)
    trailingstartshort = positionprice*(trailingpercentshort/100)
     
    trailingsteplong = positionprice*(steppercentlong/100)
    trailingstepshort = positionprice*(steppercentshort/100)
    endif
     
    if not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl           = 0
    mypositionprice = 0
    endif
    positioncount = abs(countofposition)
    if newsl > 0 then
    if positioncount > positioncount[1] then
    if longonmarket then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    else
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    endif
    if ts2sensitivity=1 then
    ts2sensitivitylong=close
    ts2sensitivityshort=close
    elsif ts2sensitivity=2 then
    ts2sensitivitylong=high
    ts2sensitivityshort=low
    elsif ts2sensitivity=3 then
    ts2sensitivitylong=low
    ts2sensitivityshort=high
    elsif ts2sensitivity=4 then
    ts2sensitivitylong=(typicalprice)
    ts2sensitivityshort=(typicalprice)
    endif
    if longonmarket then
    if newsl=0 and ts2sensitivitylong-positionprice>=trailingstartlong*pipsize then
    newsl = positionprice+trailingsteplong*pipsize
    endif
    if newsl>0 and ts2sensitivitylong-newsl>=trailingsteplong*pipsize then
    newsl = newsl+trailingsteplong*pipsize
    endif
    endif
    if shortonmarket then
    if newsl=0 and positionprice-ts2sensitivityshort>=trailingstartshort*pipsize then
    newsl = positionprice-trailingstepshort*pipsize
    endif
    if newsl>0 and newsl-ts2sensitivityshort>=trailingstepshort*pipsize then
    newsl = newsl-trailingstepshort*pipsize
    endif
    endif
    if barindex-tradeindex>1 then
    if longonmarket then
    if newsl>0 then
    sell at newsl stop
    endif
    if newsl>0 then
    if low crosses under newsl then
    sell at market
    endif
    endif
    endif
    if shortonmarket then
    if newsl>0 then
    exitshort at newsl stop
    endif
    if newsl>0 then
    if high crosses over newsl then
    exitshort at market
    endif
    endif
    endif
    endif
    mypositionprice = positionprice
    endif

    It goes to breakeven exactly as expected but then stops, doesn’t trail. In the attached image, the breakeven was at the circled candle. 6 candles later the stop is still at 11835.2. the step is .003% so it should move .35 per candle = 11837. Any thoughts on this?

    ts.jpg ts.jpg
    #150176 quote
    nonetheless
    Participant
    Master

    Ok, never mind – I just realized that acceleratorlong = .003 does not mean .003%

    I forgot because the other TS I use has a straight % value for trailingstep

    This one does trail but sooooo slowly – effectively just holds the position open with the hope of getting to the target. With a setting of .003 I might as well just use the breakeven code.

    #150180 quote
    Paul
    Participant
    Master

    Hi Nonetheless good you found the reason.

    I might still mention a few things.

    Probably it misses *pointsize at the end, this is the part I changed

    trailingstartlong = (tradeprice(countpos)*(trailingpercentlong/100))*pointsize
    trailingstartshort = (tradeprice(countpos)*(trailingpercentshort/100))*pointsize
    trailingsteplong = (tradeprice(countpos)*(steppercentlong/10000))*pointsize
    trailingstepshort = (tradeprice(countpos)*(steppercentshort/10000))*pointsize

    I also changed /100 to /10000 so steps are better manageable.  Doesn’t change results, but the *pointsize might give different results on i.e 1 euro or 2 dollar DJ charts. (the countpos needs to be changed).

    In the past I noticed that using if newsl>0 without defining longonmarket or shortonmarket sometimes, but not always, gave  a few strange results, that why I at the end of the code had it specified.

    Anyway for this part you could test 2 variations. Should have the same results.

    if (shortonmarket and newsl > 0) or (longonmarket and newsl>0) then
    if positioncount > positioncount[1] then
    if longonmarket then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    endif
    if shortonmarket then
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    endif

    or

    positioncount = abs(countofposition)
    
    if longonmarket and newsl > 0 then
    if positioncount > positioncount[1] then
    newsl = max(newsl,positionprice * newsl / mypositionprice)
    endif
    endif
    
    if shortonmarket and newsl > 0 then
    if positioncount > positioncount[1] then
    newsl = min(newsl,positionprice * newsl / mypositionprice)
    endif
    endif

    Maybe you can keep above as backup if you still find strange things trading live.

    nonetheless thanked this post
    #150189 quote
    nonetheless
    Participant
    Master

    That’s great, I’ll try both those options – thanks again!

    #177823 quote
    murre87
    Participant
    Senior

    Do we have a final version of this.

    Add to the snippet library?

Viewing 15 posts - 16 through 30 (of 30 total)
  • You must be logged in to reply to this topic.

Trailing stop fails to move


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 29 replies,
has 4 voices, and was last updated by murre87
4 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 10/26/2020
Status: Active
Attachments: 3 files
Logo Logo
Loading...