Breakeven- en trailingstop on different securities & indexes & forex
Forums › ProRealTime English forum › ProOrder support › Breakeven- en trailingstop on different securities & indexes & forex
- This topic has 79 replies, 15 voices, and was last updated 4 years ago by Paul.
-
-
05/27/2020 at 12:17 PM #133433
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!!?? 🙂
05/27/2020 at 12:45 PM #133435after 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.
1 user thanked author for this post.
05/27/2020 at 1:52 PM #133441@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.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239//-------------------------------------------------------------------------// hoofd code : BarHunter v4.5p 15m dax trick//-------------------------------------------------------------------------// dax 1 hour timeframe backtest / dax 1 minute live// spread 4// testdefparam cumulateorders = falsedefparam preloadbars = 1000timeframe (default)once positionsize = 1once mode = 1 // use [1] for 1 hour timeframe, [0] for 1 minute timeframeonce tds = 0 // off when optimising [trend detection system]// separate long/short or go bothonce longtrading =1once shorttrading =1once holiday =1once closefriday =1once 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=3lm=15// reset low timeframeif intradaybarindex=0 thentradecounter=0tradecounterlong=0tradecountershort=0tradeday=1endif// holidayif holiday thenif (month = 5 and day = 1) or (month = 12 and day >=24) thentradeday=0elsetradeday=1endifendif// set high / low points to breakif longtrading or (longtrading and shorttrading) thenlongma = average[lm](close)shortma = average[sm](close)endifif shorttrading or (longtrading and shorttrading) thenlongma = average[lm](close)shortma = average[sm](close)endif// trend detection systemif tds=0 thentrendup=1trenddown=1elseif tds=1 thentrendup=(average[10](close)>average[10](close)[1])trenddown=(average[10](close)<average[10](close)[1])elseif tds=2 thenperiod= 2inner = 2*weightedaverage[round( period/2)](typicalprice)-weightedaverage[period](typicalprice)hull = weightedaverage[round(sqrt(period))](inner)trendup = hull > hull[1]trenddown = hull < hull[1]elseif tds=3 thenperiod= 2inner = 2*weightedaverage[round( period/2)](totalprice)-weightedaverage[period](totalprice)hull = weightedaverage[round(sqrt(period))](inner)trendup = hull > hull[1]trenddown = hull < hull[1]endifendifendifendif// conditionscondbuy=intradaybarindex >= barnumberlongcondbuy=condbuy and shortma crosses over longmacondbuy=condbuy and trendupcondsell=intradaybarindex >= barnumbershortcondsell=condsell and shortma crosses under longmacondsell=condsell and trenddowntimeframe (default)// entry criteriaif mode then // mode[1] backtesting on 1 hour timeframeif tradeday and tradecounter < 100 thenif (longtrading and not shorttrading) or (longtrading and shorttrading) thenif condbuy and tradecounterlong < 1 and (tradecounter<2 and (intradaybarindex < barnumberlong+4)) thenbuy positionsize contract at markettradecounter=tradecounter+1endifendifif (shorttrading and not longtrading) or (longtrading and shorttrading) thenif condsell and tradecountershort < 1 and (tradecounter<2 and (intradaybarindex < barnumbershort+4)) thensellshort positionsize contract at markettradecounter=tradecounter+1endifendifendifelse // mode[0] running demo / live on 1 minute timeframeif tradeday and tradecounter < 1 thenif (longtrading and not shorttrading) or (longtrading and shorttrading) thenif condbuy and tradecounterlong < 1 thenbuy positionsize contract at markettradecounter=tradecounter+1endifendifif (shorttrading and not longtrading) or (longtrading and shorttrading) thenif condsell and tradecountershort < 1 thensellshort positionsize contract at markettradecounter=tradecounter+1endifendifendifendif//timeframe (1 hour, updateonclose)// trailing atr stop on high timeframeonce trailingstoptype = 1 // trailing stop - 0 off, 1 ononce trailingstoplong = 5 // trailing stop atr relative distanceonce trailingstopshort = 5 // trailing stop atr relative distanceonce atrtrailingperiod = 14 // atr parameter valueonce minstop = 10 // minimum trailing stop distance//----------------------------------------------atrtrail = averagetruerange[atrtrailingperiod]((close/10)*pipsize)/1000trailingstartl = round(atrtrail*trailingstoplong)trailingstarts = round(atrtrail*trailingstopshort)if trailingstoptype = 1 thentgl =trailingstartltgs=trailingstartsif not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket)) thenmaxprice = 0minprice = closenewsl = 0endifif longonmarket thenmaxprice = max(maxprice,close)if maxprice-tradeprice(1)>=tgl*pointsize thenif maxprice-tradeprice(1)>=minstop thennewsl = maxprice-tgl*pointsizeelsenewsl = maxprice - minstop*pointsizeendifendifendifif shortonmarket thenminprice = min(minprice,close)if tradeprice(1)-minprice>=tgs*pointsize thenif tradeprice(1)-minprice>=minstop thennewsl = minprice+tgs*pointsizeelsenewsl = minprice + minstop*pointsizeendifendifendifendiftimeframe (default)// trailing atr stop exits on low timeframeif longonmarket thenif newsl>0 thensell at newsl stopendifendifif shortonmarket thenif newsl>0 thenexitshort at newsl stopendifendif// close to reduce risk in the weekendif closefriday thenif onmarket thenif (dayofweek=5 and hour=22) thensell at marketexitshort at marketendifendifendif// stoploss & profit targetset target %profit 2set stop %loss 2// display days in marketif displaydim thenif (not onmarket or ((longonmarket and shortonmarket[1]) or (longonmarket[1] and shortonmarket))) thendim=0endifif not ( dayofweek=1 and hour <= 1) thenif onmarket thenif openday <> openday[1] thendim = dim + 1endifendifendifif onmarket and dayofweek=1 and hour=1 then//dim=-1 // shows when position is active on monday first hourendifif onmarket and dim>=maxdim thensell at marketexitshort at marketendifendif//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 intradaybarindexgraphonprice longmagraphonprice shortma1 user thanked author for this post.
05/27/2020 at 2:52 PM #133454well didn’t expect that!
here’s a new one , same code, change in moving average.
2 users thanked author for this post.
06/13/2020 at 12:08 PM #1358071 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??
06/13/2020 at 6:30 PM #135841@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!
06/14/2020 at 7:27 PM #135918Hi @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:
1234567SL = 0.75 // % stop lossPT = 1.50 // % profit targetTS = .3 // % trailing stopBESG = .15 // % break even stop gainBESL = 0.00 // % break even stop levelsm = 20lm = 40Or for a higher win rate, v2
1234567SL = 0.75 // % stop lossPT = 1.50 // % profit targetTS = .2 // % trailing stopBESG = .15 // % break even stop gainBESL = 0.00 // % break even stop levelsm = 20lm = 30For 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,
06/14/2020 at 9:32 PM #135931For 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.
07/06/2020 at 8:51 AM #138534Hi 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
07/06/2020 at 11:36 AM #138545breakeven 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!
07/06/2020 at 11:49 AM #13854607/07/2020 at 12:39 PM #138629hi 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.
1234567891011121314151617if barindex=0 thentradecounterlong=0endifif not longonmarket thenlbc=0 // long bar counterendifif longonmarket thenlbc=lbc+1hh=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?
07/07/2020 at 1:24 PM #138635test setup dow or dax 1m tf
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647defparam cumulateorders = falsedefparam preloadbars=0c1=average[60](close)c2=average[80](close)condbuy=barindex>100 and c1 crosses over c2timeframe (5 minutes,updateonclose)st=supertrend[4,2]timeframe (default)condbuy = condbuy and close>stif barindex=0 thentradecounterlong=0endifif not longonmarket thenlbc=0 // long bar counterendifif longonmarket thenlbc=lbc+1hh=highest[lbc](high)mfeUP=round((hh-tradeprice(1)))*pipvalueif mfeUP>0 thenmfelong=mfeUPelsemfelong=0endifelsemfelong=0endif//if condbuy and not longonmarket thenbuy 1 contract at markettradecounterlong=tradecounterlong + 1endifset stop ploss 100set target pprofit 100mfelong=mfelong//graph tradecounterlong coloured(255,0,0,255)graph mfelong coloured(0,0,255,255)07/07/2020 at 4:00 PM #13865307/07/2020 at 5:39 PM #138670Hey 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!
-
AuthorPosts