Breakeven- en trailingstop on different securities & indexes & forex

Viewing 15 posts - 61 through 75 (of 80 total)
  • Author
    Posts
  • #133433 quote
    GraHal
    Participant
    Master

    wasn’t this a test version?

    Maybe that was why I put ?? in the title.

    Wide spread overnight does not necessarily have to be bad thing provided the wide spread is not accompanied by illogical volatility which a System has no chance of predicting?

    Spread at 6 overnight may be better compared to 40 to 80 points movement on a 1 min bar when spread is 2.4   and the professionals are tricking / faking us  and our Systems into taking the wrong direction!? 🙁

    Then 5 mins or so later …  oh sorry you’re going the wrong way again now, us pro’s have reversed our positions … you must try and keep up with us if you want to make money!!?? 🙂

    #133435 quote
    Paul
    Participant
    Master

    after posting ofcouse I see the first line of the code… 🙂

    // test trailingstop and breakeven on the dax

    indeed high spread doesn’t need to be a bad thing. Looking at barhunter it acts only when the spread is the highest and still it preforms!

    About tricking, something to use with barhunter? Maybe there are special times where the markets makes a move to do the opposite? Like before closing or opening, or of other markets? I don’t give it much chance but if it can be coded quick it would be fun to test on a higher timeframe.

    GraHal thanked this post
    #133441 quote
    Paul
    Participant
    Master

    @grahal, there’s a quick try on 15min dax

    It searches for the bar(=time) of the crosses from the moving average.

    It can then go 1x long and 1x short within the next xx (=4) bars. Max trades is 2 a day. I didn’t look at sl/pt/ts and just took some averages and tested only 15m.

    //-------------------------------------------------------------------------
    // hoofd code : BarHunter v4.5p 15m dax trick 
    //-------------------------------------------------------------------------
    // dax 1 hour timeframe backtest / dax 1 minute live
    // spread 4
    
    // test
    
    defparam cumulateorders = false
    defparam preloadbars    = 1000
    
    timeframe (default)
    
    once positionsize = 1
    
    once mode     = 1 // use [1] for 1 hour timeframe, [0] for 1 minute timeframe
    
    once tds      = 0 // off when optimising [trend detection system]
    
    // separate long/short or go both
    once longtrading  =1
    once shorttrading =1
    
    once holiday      =1
    once closefriday  =1
    
    once displaydim   =1 // displays the number of days in market (activated graph)
    once maxdim       =5 // maximum days in market (first day = 0)
    
    // select which intradaybar should be analysed (depends on timeframe settings)
    once barnumberlong =13 //long (timezone dependent)
    once barnumbershort=13 //short (timezone dependent)
    
    
    sm=3
    lm=15
    
    // reset low timeframe
    if intradaybarindex=0 then
    tradecounter=0
    tradecounterlong=0
    tradecountershort=0
    tradeday=1
    endif
    
    // holiday
    if holiday then
    if (month = 5 and day = 1) or (month = 12 and day >=24) then
    tradeday=0
    else
    tradeday=1
    endif
    endif
    
    // set high / low points to break
    if longtrading or (longtrading and shorttrading) then
    longma = average[lm](close)
    shortma = average[sm](close)
    endif
    if shorttrading or (longtrading and shorttrading) then
    longma = average[lm](close)
    shortma = average[sm](close)
    endif
    
    // trend detection system
    if tds=0 then
    trendup=1
    trenddown=1
    else
    if tds=1 then
    trendup=(average[10](close)>average[10](close)[1])
    trenddown=(average[10](close)<average[10](close)[1])
    else
    if tds=2 then
    period= 2
    inner = 2*weightedaverage[round( period/2)](typicalprice)-weightedaverage[period](typicalprice)
    hull = weightedaverage[round(sqrt(period))](inner)
    trendup = hull > hull[1]
    trenddown = hull < hull[1]
    else
    if tds=3 then
    period= 2
    inner = 2*weightedaverage[round( period/2)](totalprice)-weightedaverage[period](totalprice)
    hull = weightedaverage[round(sqrt(period))](inner)
    trendup = hull > hull[1]
    trenddown = hull < hull[1]
    endif
    endif
    endif
    endif
    
    // conditions
    condbuy=intradaybarindex >= barnumberlong
    condbuy=condbuy and shortma crosses over longma
    condbuy=condbuy and trendup
    
    condsell=intradaybarindex >= barnumbershort
    condsell=condsell and shortma crosses under longma
    condsell=condsell and trenddown
    
    timeframe (default)
    // entry criteria
    if mode then // mode[1] backtesting on 1 hour timeframe
    if tradeday and tradecounter < 100 then
    if (longtrading and not shorttrading) or (longtrading and shorttrading) then
    if condbuy and tradecounterlong < 1 and (tradecounter<2 and (intradaybarindex < barnumberlong+4)) then
    buy positionsize contract at market
    tradecounter=tradecounter+1
    endif
    endif
    if (shorttrading and not longtrading) or (longtrading and shorttrading) then
    if condsell and tradecountershort < 1 and (tradecounter<2 and (intradaybarindex < barnumbershort+4)) then
    sellshort positionsize contract at market
    tradecounter=tradecounter+1
    endif
    endif
    endif
    else        // mode[0] running demo / live on 1 minute timeframe
    if tradeday and tradecounter < 1 then
    if (longtrading and not shorttrading) or (longtrading and shorttrading) then
    if condbuy and tradecounterlong < 1 then
    buy positionsize contract at market
    tradecounter=tradecounter+1
    endif
    endif
    if (shorttrading and not longtrading) or (longtrading and shorttrading) then
    if condsell and tradecountershort < 1 then
    sellshort positionsize contract at market
    tradecounter=tradecounter+1
    endif
    endif
    endif
    endif
    
    //timeframe (1 hour, updateonclose)
    
    // trailing atr stop on high timeframe
    once trailingstoptype     = 1    // trailing stop - 0 off, 1 on
    once trailingstoplong     = 5    // trailing stop atr relative distance
    once trailingstopshort    = 5    // trailing stop atr relative distance
    
    once atrtrailingperiod    = 14   // atr parameter value
    once minstop              = 10   // minimum trailing stop distance
    //----------------------------------------------
    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 or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) then
    maxprice = 0
    minprice = close
    newsl = 0
    endif
    if longonmarket then
    maxprice = max(maxprice,close)
    if maxprice-tradeprice(1)>=tgl*pointsize then
    if maxprice-tradeprice(1)>=minstop then
    newsl = maxprice-tgl*pointsize
    else
    newsl = 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
    newsl = minprice+tgs*pointsize
    else
    newsl = minprice + minstop*pointsize
    endif
    endif
    endif
    endif
    
    timeframe (default)
    
    // trailing atr stop exits on low timeframe
    if longonmarket then
    if newsl>0 then
    sell at newsl stop
    endif
    endif
    if shortonmarket then
    if newsl>0 then
    exitshort at newsl stop
    endif
    endif
    
    // close to reduce risk in the weekend
    if closefriday then
    if onmarket then
    if (dayofweek=5 and hour=22) then
    sell at market
    exitshort at market
    endif
    endif
    endif
    
    // stoploss & profit target
    set target %profit 2
    set stop %loss 2
    
    // display days in market
    if displaydim then
    if (not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket))) then
    dim=0
    endif
    if  not ( dayofweek=1 and hour <= 1) then
    if onmarket then
    if openday <> openday[1] then
    dim = dim + 1
    endif
    endif
    endif
    if onmarket and dayofweek=1 and hour=1 then
    //dim=-1 // shows when position is active on monday first hour
    endif
    if onmarket and dim>=maxdim then
    sell at market
    exitshort at market
    endif
    endif
    
    //graph dim // display days in market
    //graphonprice newsl coloured(0,0,255,255) as "trailingstop atr"
    
    //graphonprice breakvaluelong coloured(121,141,35,255) as "breakpoint"
    //graphonprice breakvalueshort coloured(121,141,35,255) as "breakpoint"
    //graph breakvaluelong coloured(255,0,0,255) as "breakvaluelong"
    //graph breakvalueshort coloured(255,0,0,255) as "breakvalueshort"
    
    //graph barindex-tradeindex
    //graph intradaybarindex
    
    graphonprice longma
    graphonprice shortma
    GraHal thanked this post
    #133454 quote
    Paul
    Participant
    Master

    well didn’t expect that!

    here’s a new one , same code, change in moving average.

    GraHal and nonetheless thanked this post
    #135807 quote
    GraHal
    Participant
    Master

    1 month on this one is still doing very good … see attached.

    I put the equity curve on 15 mins TF so you could see the steadily increasing equity curve!


    @Paul
    what lines of code cause most trades to open between 230000 and 240000 (but there a few after 240000 and before 020000)? See Paul 3 to see trade open times.

    I did search for time, hour etc.  It can’t be coincidence … the time band over which trades open is too regular to be a random occurence??

    #135841 quote
    Paul
    Participant
    Master

    @GraHal That there’s sometimes a trade between 23h-24h could be because of the weekend and how it handles the first hour on monday, perhaps in combination with uk settings? Because the trade is taking on sunday 23h on 31 may & 7 june. Using extra criteria like dayofweek should work to skip those trades on sunday. Nice find btw. Didn’t expect that was necessary!

    #135918 quote
    Scooby
    Participant
    Senior

    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:

    Or for a higher win rate, v2

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

    Hi @nonetheless  !

    Did you continue this strategy ?

    I would like to do some test with it but I did’nt find the initial post of it. Can you share these 2 versions please ? 🙂

     

    Thanks in advance,

    #135931 quote
    GraHal
    Participant
    Master

    For it not to have blown up in 14 days of forward testing

    Isn’t it 30 full days trading since 12 May?

    Enthusiasm gets sapped by keep trying and trying with the same old code / strategy? Variety is the spice of life and sometimes the weirdest stuff works on odd timeframes and / or Instruments?? 🙂

    Yeah thanks … I’ll try your settings also.

    #138534 quote
    zilliq
    Participant
    Master

    Hi Guys,

    As we can’t do partial exits with IG (Who will be better for trailingstop), did you compare if it’s better to have a trailing stop / Breakeven or to exit all in one time with a R/R of 1/1 or 2/1 for example (No offense of course)

    In my experience actually, I don’t have better results with TS/BE but may be I’m wrong

    What’s your experience ?

    SeeU

    #138545 quote
    Paul
    Participant
    Master

    breakeven I agree fully. Giving higher winchance, but often really small wins. Could better be used i.e. to lower the stoploss in half. Trailingstop is a must for me. Always open for improvements, so let’s see your exit criteria & calculation so I can compare in a strategy!

    #138546 quote
    zilliq
    Participant
    Master

    Hi @Paul

    I think we need to use a classical/simple algos code and compare results with and without TS/BE.

    If I have time tomorrow I willl do that 😉

    SeeU

    #138629 quote
    Paul
    Participant
    Master

    hi zilliq

    meantime I wanted to try to have a dynamic pt but stumbled on a problem.

    goal is to log the highest mfe for each (long) trade.

    second is to have a tradecounterlong

    both above are done.

    But then I need an average MFE runup based on the highest mfe from each trade. I can’t get through that part.

    With average there could be a factor x as profittarget. But how to get an average?

    That average could also be used as a dynamic level to activate the trailingstop.

    Here’s what I have.

    if barindex=0 then
    tradecounterlong=0
    endif
    
    if not longonmarket then
    lbc=0 // long bar counter
    endif
    
    if longonmarket then
    lbc=lbc+1
    hh=highest[lbc](high)
    mfe=(round((hh-tradeprice(1)))*pipvalue)
    endif
    
    //added tradecounterlong=tradecounterlong + 1 when bought.
    //graph tradecounterlong coloured(255,0,0,255)
    //graph mfe coloured(0,0,255,255)

    to code above could also be added to reset mfe to zero if there short or not onmarket.

    any advise here on the average part?

    #138635 quote
    Paul
    Participant
    Master

    test setup dow or dax 1m tf

    defparam cumulateorders = false
    defparam preloadbars=0
    
    c1=average[60](close)
    c2=average[80](close)
    
    condbuy=barindex>100 and c1 crosses over c2
    
    timeframe (5 minutes,updateonclose)
    st=supertrend[4,2]
    timeframe (default)
    
    condbuy = condbuy and close>st
    
    if barindex=0 then
    tradecounterlong=0
    endif
    
    if not longonmarket then
    lbc=0 // long bar counter
    endif
    
    if longonmarket then
    lbc=lbc+1
    hh=highest[lbc](high)
    mfeUP=round((hh-tradeprice(1)))*pipvalue
    if mfeUP>0 then
    mfelong=mfeUP
    else
    mfelong=0
    endif
    else
    mfelong=0
    endif
    
    //
    if condbuy and not longonmarket then
    buy 1 contract at market
    tradecounterlong=tradecounterlong + 1
    endif
    
    set stop ploss 100
    set target pprofit 100
    
    mfelong=mfelong
    //graph tradecounterlong coloured(255,0,0,255)
    graph mfelong coloured(0,0,255,255)
    #138653 quote
    zilliq
    Participant
    Master

    Hi Paul

    Why do you want to a high MFE ? (And not a small MAE, or small Max drawdown an so on ) ?

    #138670 quote
    Paul
    Participant
    Master

    Hey Zilliq, This is the first part but goal is to get mfe & mae for long & short separate working. A.t.m. just want to have the calculation right and then later look what’s preferable.

    Does it make sense and can it improve a strategy? I don’t know.

    But the problem, it needs to take the highest mfe from each long trade, added together and divide that by the amount of long trades. Any ideas? Sounds simple but I can’t find the right way yet!

Viewing 15 posts - 61 through 75 (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...