Breakeven- en trailingstop on different securities & indexes & forex

Viewing 15 posts - 46 through 60 (of 80 total)
  • Author
    Posts
  • #131881 quote
    Paul
    Participant
    Master

    and an trailingstop with percentage, but with 3 steps.  Didn’t optimise. i.e.

    default trailingstop 2% (it needs to reach a positionperformance of 2%, to close on 2% retracement)

    if positionperformance > 3% then change trailingstop to 1%

    if positionperformance > 4% then change trailingstop to 0.5%

    keewee and swedshare thanked this post
    #132646 quote
    auvergnat
    Participant
    Veteran

    Hi Nonetheless, thks for this nice code on post #126280 but I tried with no succes on live IG, rejected order something wrong !! Can you watch ?

    #132653 quote
    GraHal
    Participant
    Master

    I’ve just set it going on Forward Test.

    Seems to be doing well … results attached.

    #132657 quote
    auvergnat
    Participant
    Veteran

    Not this one, post #126280 is on TF 5 minutes. I just try to change stop loss condition (if..) to classic SL code (I have an IG account with SL guaranteed) but same results…

    / Definition of code parameters
    DEFPARAM CumulateOrders = FALSE // Cumulating positions deactivated
    DEFPARAM preloadbars = 500
    //Money Management DOW
    MM = 0 // = 0 for optimization
    if MM = 0 then
    positionsize=1
    ENDIF
    if MM = 1 then
    ONCE startpositionsize = 1
    ONCE factor = 50 // factor of 10 means margin will increase/decrease @ 10% of strategy profit; factor 20 = 5% etc
    ONCE factor2 = 60 // tier 2 factor
    ONCE margin = (close*.005) // tier 1 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE margin2 = (close*.01)// tier 2 margin value of 1 contract in instrument currency; change decimal according to available leverage
    ONCE tier1 = 55 // DOW €1 IG first tier margin limit
    ONCE maxpositionsize = 550 // DOW €1 IG tier 2 margin limit
    ONCE minpositionsize = .2 // enter minimum position allowed
    IF Not OnMarket THEN
    positionsize = startpositionsize + Strategyprofit/(factor*margin)
    ENDIF
    IF Not OnMarket THEN
    IF startpositionsize + Strategyprofit/(factor*margin) > tier1 then
    positionsize = (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 //incorporating tier 2 margin
    ENDIF
    IF Not OnMarket THEN
    if startpositionsize + Strategyprofit/(factor*margin) < minpositionsize THEN
    positionsize = minpositionsize //keeps positionsize from going below allowed minimum
    ENDIF
    IF (((startpositionsize + (Strategyprofit/(factor*margin))-tier1)*(factor*margin))/(factor2*margin2)) + tier1 > maxpositionsize then
    positionsize = maxpositionsize// keeps positionsize from going above IG tier 2 margin limit
    ENDIF
    ENDIF
    ENDIF
    ENDIF
    
    //once enableSL = 1 // stop loss
    once enablePT = 1 // profit target
    once enableTS = 1 // trailing stop
    once enableBE = 1 // breakeven stop
    
    //once displaySL = 1 // stop loss
    //once displayPT = 1 // profit target
    //once displayTS = 1 // trailing stop
    //once displayBE = 1 // breakeven stop
    
    SL = 1.7//1.9 // % stop loss
    PT = 2.4//2.3 // % profit target
    TS = 0.4//0.35//0.26 // % trailing stop
    BESG = 0.5//0.35//0.25 // % break even stop gain
    BESL = 0.2//0.40//0.00 // % break even stop level
    // underlaying security / index / forex
    // profittargets and stoploss have to match the lines
    // 0.01 FOREX [i.e. GBPUSD=0.01]
    // 1.00 SECURITIES [i.e. aapl=1 ;
    // 100.00 INDEXES [i.e. dax=100]
    
    // 100=XAUUSD
    // 100=CL US Crude
    // DAX=100
    
    underlaying=50//100
    
    // reset at start
    //if intradaybarindex=0 then
    //longtradecounter=0
    //shorttradecounter=0
    //endif
    
    //pclong = longtradecounter<1
    //pcshort = shorttradecounter<1
    
    TIMEFRAME(120 MINUTES,updateonclose)
    Period= 495
    inner = 2*weightedaverage[round( Period/2)](typicalprice)-weightedaverage[Period](typicalprice)
    HULLa = weightedaverage[round(sqrt(Period))](inner)
    c1 = HULLa > HULLa[1]
    c2 = HULLa < HULLa[1]
    
    indicator1 = SuperTrend[8,6]
    c3 = (close > indicator1)
    c4 = (close < indicator1)
    
    ma = average[60,3](close)
    c11 = ma > ma[1]
    c12 = ma < ma[1]
    
    //Stochastic RSI | indicator
    lengthRSI = 15 //RSI period
    lengthStoch = 9 //Stochastic period
    smoothK = 10 //Smooth signal of stochastic RSI
    smoothD = 5 //Smooth signal of smoothed stochastic RSI
    myRSI = RSI[lengthRSI](close)
    MinRSI = lowest[lengthStoch](myrsi)
    MaxRSI = highest[lengthStoch](myrsi)
    StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
    K = average[smoothK](stochrsi)*100
    D = average[smoothD](K)
    c13 = K>D
    c14 = K<D
    
    TIMEFRAME(30 minutes,updateonclose)
    indicator5 = Average[2](typicalPrice)
    indicator6 = Average[7](typicalPrice)
    c15 = (indicator5 > indicator6)
    c16 = (indicator5 < indicator6)
    
    TIMEFRAME(15 minutes,updateonclose)
    indicator2 = Average[4](typicalPrice)
    indicator3 = Average[8](typicalPrice)
    c7 = (indicator2 > indicator3)
    c8 = (indicator2 < indicator3)
    
    ma2 = average[25,1](close)
    c17 = ma2 > ma2[1]
    c18 = ma2 < ma2[1]
    
    Periodc= 23
    innerc = 2*weightedaverage[round( Periodc/2)](typicalprice)-weightedaverage[Periodc](typicalprice)
    HULLc = weightedaverage[round(sqrt(Periodc))](innerc)
    c9 = HULLc > HULLc[1]
    c10 = HULLc < HULLc[1]
    
    TIMEFRAME(10 minutes)
    indicator1a = SuperTrend[2,7]
    c19 = (close > indicator1a)
    c20 = (close < indicator1a)
    
    TIMEFRAME (5 minutes)//(default)
    //Stochastic RSI | indicator
    lengthRSIa = 3 //RSI period
    lengthStocha = 6 //Stochastic period
    smoothKa = 9 //Smooth signal of stochastic RSI
    smoothDa = 3 //Smooth signal of smoothed stochastic RSI
    myRSIa = RSI[lengthRSIa](close)
    MinRSIa = lowest[lengthStocha](myrsia)
    MaxRSIa = highest[lengthStocha](myrsia)
    StochRSIa = (myRSIa-MinRSIa) / (MaxRSIa-MinRSIa)
    Ka = average[smoothKa](stochrsia)*100
    Da = average[smoothDa](Ka)
    c23 = Ka>Da
    c24 = Ka<Da
    
    ma3 = average[15,3](close)
    c21 = ma3 > ma3[1]
    c22 = ma3 < ma3[1]
    
    Periodb= 15
    innerb = 2*weightedaverage[round( Periodb/2)](typicalprice)-weightedaverage[Periodb](typicalprice)
    HULLb = weightedaverage[round(sqrt(Periodb))](innerb)
    c5 = HULLb > HULLb[1]and HULLb[1]<HULLb[2]
    c6 = HULLb < HULLb[1]and HULLb[1]>HULLb[2]
    
    // Conditions to enter long positions
    IF c1 AND C3 AND C5 and c7 and c9 and c11 and c13 and c15 and c17 and c19 and c21 and c23 THEN
    BUY positionsize CONTRACT AT MARKET
    set stop %loss SL
    //longtradecounter=longtradecounter+1
    ENDIF
    
    // Conditions to enter short positions
    IF c2 AND C4 AND C6 and c8 and c10 and c12 and c14 and c16 and c18 and c20 and c22 and c24 THEN
    SELLSHORT positionsize CONTRACT AT MARKET
    set stop %loss SL
    //shorttradecounter=shorttradecounter+1
    ENDIF
    
    //================== exit in profit
    if longonmarket and C6 and c8 and close>positionprice then
    sell at market
    endif
    
    If shortonmarket and C5 and c7 and close<positionprice then
    exitshort at market
    endif
    
    //==============exit at loss
    if longonmarket AND c2 and c6 and close<positionprice then
    sell at market
    endif
    If shortonmarket and c1 and c5 and close>positionprice then
    exitshort at market
    endif
    
    // to set & display stoploss
    //if enableSL then
    //set stop %loss SL
    //if displaysl then
    //if not onmarket then
    //sloss=0
    //elsif ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    //sloss=0
    //endif
    //if onmarket then
    //if longonmarket then
    //sloss=tradeprice(1)-((tradeprice(1)*SL)/underlaying)*pointsize
    //endif
    //if shortonmarket then
    //sloss=tradeprice(1)+((tradeprice(1)*SL)/underlaying)*pointsize
    //endif
    //endif
    //graphonprice sloss coloured(255,0,0,255) as “stoploss”
    //sloss=sloss
    //endif
    //endif
    
    // to set & display profittarget
    if enablePT then
    set target %profit PT
    //if displaypt then
    //if not onmarket then
    //ptarget=0
    //elsif ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    //ptarget=0
    //endif
    //if onmarket then
    //if longonmarket then
    //ptarget=tradeprice(1)+((tradeprice(1)*PT)/underlaying)*pointsize
    //endif
    //if shortonmarket then
    //ptarget=tradeprice(1)-((tradeprice(1)*PT)/underlaying)*pointsize
    //endif
    //endif
    //graphonprice ptarget coloured(121,141,35,255) as “profittarget”
    //ptarget=ptarget
    //endif
    endif
    
    // trailing stop
    if enableTS then
    trailingstop = (tradeprice/100)*TS
    if not onmarket then
    maxprice=0
    minprice=close
    priceexit=0
    endif
    if ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    maxprice=0
    minprice=close
    priceexit=0
    endif
    if longonmarket then
    maxprice=max(maxprice,close)
    if maxprice-tradeprice(1)>=(trailingstop) then
    priceexit=maxprice-(trailingstop/(underlaying/100))*pointsize
    endif
    endif
    if shortonmarket then
    minprice=min(minprice,close)
    if tradeprice(1)-minprice>=(trailingstop) then
    priceexit=minprice+(trailingstop/(underlaying/100))*pointsize
    endif
    endif
    if longonmarket and priceexit>0 then
    sell at priceexit stop
    endif
    if shortonmarket and priceexit>0 then
    exitshort at priceexit stop
    endif
    //if displayTS then
    //priceexit=priceexit
    //graphonprice priceexit coloured(0,0,255,255) as “trailingstop”
    //endif
    endif
    
    // break even stop
    if enableBE then
    if not onmarket then
    newsl=0
    endif
    if ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    newsl=0
    endif
    if longonmarket then
    if close-tradeprice(1)>=(((tradeprice(1)/100)*BESG)/(underlaying/100))*pointsize then
    newsl=tradeprice(1)+(((tradeprice(1)/100)*BESL)/(underlaying/100))*pointsize
    endif
    endif
    if shortonmarket then
    if tradeprice(1)-close>=(((tradeprice(1)/100)*BESG)/(underlaying/100))*pointsize then
    newsl=tradeprice(1)-(((tradeprice(1)/100)*BESL)/(underlaying/100))*pointsize
    endif
    endif
    if longonmarket and newsl>0 then
    sell at newsl stop
    endif
    if shortonmarket and newsl>0 then
    exitshort at newsl stop
    endif
    //if displayBE then
    //newsl=newsl
    //graphonprice newsl coloured(244,102,27,255) as “breakevenstop”
    //endif
    endif
    
    //graph (positionperf*100)coloured(0,0,0,255) as “positionperformance”
    #132658 quote
    auvergnat
    Participant
    Veteran

    this code works fine on backtest on Dow 5TF but noting on live. If somebody can help me ?

    #132659 quote
    swedshare
    Participant
    Senior

    This part doesn’t look right – “underlaying=50//100”

    #132666 quote
    robertogozzi
    Moderator
    Master

    @auvergnat

    below you have certainly read some of the rules required by this forum.

    One of them reads “Always use the ‘Insert PRT Code’ button when putting code in your posts to make it easier for others to read.”. Please stick to it. Thank you 🙂

    auvergnat thanked this post
    #132675 quote
    auvergnat
    Participant
    Veteran

    with 100 same result in live = reject

    #132686 quote
    auvergnat
    Participant
    Veteran

    I restart from scratch and it would seem it is ok if I put after buy and sellshort orders :

    set stop %loss 1.7
    set target %profit 2.4

    instead of :

    if enableSL then
    set stop %loss SL

    ….

    #132799 quote
    zilliq
    Participant
    Master

    Hi @Paul

    Thanks for your nice work !

    Have you try to compare a strategy with and without breakeven, in a backtest on in Sample and Walk Forward In/OOS  ?

    Because in my experience it is often less interesting to be stop/lose frequentely on Breakeven than to have a bigger stop to let the trade breathe. May be to be at your Breakeven at x ATR could help instead a “classic” Breakeven at x Pips ?

    Have a nice day

    #132814 quote
    Paul
    Participant
    Master

    Hi zilliq

    Have you try to compare a strategy with and without breakeven, in a backtest on in Sample and Walk Forward In/OOS  ?

    no, because i’am in general not a fan of such approach. Again additional choices, how many reputations, which %, linked or not and if you found something and take the last parameters next question is when to run again? It’s very time consuming.

    May be to be at your Breakeven at x ATR could help instead a “classic” Breakeven at x Pips

    yeah could very well help. Something to test!

    Take care

    zilliq thanked this post
    #133376 quote
    nonetheless
    Participant
    Master

    Hi @auvergnat, the code I posted in #1260280 was an unfinished test. The latest working version of that is here: #125210

    #133394 quote
    GraHal
    Participant
    Master

    Seems to be doing well

    30 sec TF still looking good … 14 days Forward Test attached.

    #133425 quote
    Paul
    Participant
    Master

    wasn’t this a test version?  It takes 2 signals, 1 long and 1 short after 0h at the most expensive time and let the last one run. Didn’t expect it would have any success.

    Thanks for the post!

    #133429 quote
    nonetheless
    Participant
    Master

    Hi @GraHal, every time I say ‘no more’ to sub-1m TFs I seem to get drawn back in. It’s all your fault.

    Anyway, I did a quick and dirty optimisation and you might want to try the following values:

    SL   = 0.75 // % stop loss
    PT   = 1.50 // % profit target
    TS   = .3 // % trailing stop
    BESG = .15 // % break even stop gain
    BESL = 0.00 // % break even stop level
    sm = 20
    lm = 40

    Or for a higher win rate, v2

    SL   = 0.75 // % stop loss
    PT   = 1.50 // % profit target
    TS   = .2 // % trailing stop
    BESG = .15 // % break even stop gain
    BESL = 0.00 // % break even stop level
    sm = 20
    lm = 30

    For it not to have blown up in 14 days of forward testing is good going – maybe it’s a cash cow?

    swedshare and Paul thanked this post
Viewing 15 posts - 46 through 60 (of 80 total)
  • You must be logged in to reply to this topic.

Breakeven- en trailingstop on different securities & indexes & forex


ProOrder support

New Reply
Author
author-avatar
Paul @micky75d Participant
Summary

This topic contains 79 replies,
has 15 voices, and was last updated by Paul
5 years, 6 months ago.

Topic Details
Forum: ProOrder support
Language: English
Started: 02/05/2019
Status: Active
Attachments: 34 files
Logo Logo
Loading...