How to create a breakout box between 2 hours, Code please?
Forums › ProRealTime English forum › ProOrder support › How to create a breakout box between 2 hours, Code please?
- This topic has 56 replies, 5 voices, and was last updated 6 years ago by robertogozzi.
Tagged: BreakOut
-
-
05/21/2018 at 3:00 PM #71015
I have searched this site, gone through the replies by Nicolas, watched the video various times, checked youtube comments and sections, but I can’t seem to find the code for the “How to create a breakout box between 2 hours” ?
I would then apply the code I was trying to develop, into an automated system.
I was looking at the 5 minute chart, I was trying to build a breakout box for 11pm-6am. It would reset each day, and show high and low between the set times each day, see indicator below that somebody else wrote, but I have amended;
1234567891011121314if time = 061000 then //x1= barindex[0] //x2 = barindex[86] //yh = highest[86](high)yL=lowest[86](low)drawsegment(x1,yh,x2,yh) coloured (0,0,255)drawsegment(x1,yL,x2,yL) coloured (255,0,0)// set text offset from lineos = 4*pipsizedrawtext("#yh#",barindex,yh+os,SansSerif,bold,20) coloured(0,0,0)drawtext("#yL#",barindex,yL-os,SansSerif,bold,20) coloured(0,0,0)endifreturn yh as "hi" ,yL as "Lo"The code would work out the high and low between these times, 11pm-6am, and only trade between 8am and 8pm, it would close all trades at 9pm.
It would Buy, if the price crosses over the high, by 2 points, or sell, if the price crosses under the low, by 2 points.
Only 1 buy allowed per day and 1 sell allowed per day.
Stop loss 15, target 15.
I have read various topics and codes, it seems fairly straight forward, and is covered in various posts by various people, but not all together, I have tried to piece the codes together, but I can’t seem to make it all work. 🙁
Any help would be much appreaciated. 🙂
05/22/2018 at 7:00 AM #71043This is basically, an Open Range Break Out strategy, this could be coded as follows:
1234567891011121314151617181920212223242526272829303132333435defparam flatafter = 210000if longonmarket thenalreadybuy=1endifif shortonmarket thenalreadysell=1endifif intradaybarindex=0 thenalreadybuy=0alreadysell=0endifif time = 061000 thenyh = highest[86](high)yL=lowest[86](low)os = 2*pipsizeendiftcondition = time>080000 and time<200000if tcondition thenif close<yh+os and not alreadybuy thenbuy 1 contract at yh+os stopendifif close>yl+os and not alreadysell thensellshort 1 contract at yl-os stopendifendifset stop ploss 15set target pprofit 151 user thanked author for this post.
05/22/2018 at 9:05 AM #7107607/05/2018 at 9:42 AM #75269Nicholas,
I have been using the code as above and it’s working well. 😉
I have been through the pdf’s below, but can’ find what I am looking for.
- Programming Guide – Indicators & Basic Functions (ProBuilder)
- Programming Guide – Trading Systems (ProBacktest & ProOrder)
I only want, 1 buy allowed per day and 1 sell allowed per day which is working, but is it possible to insert another piece of code, to amend that slightly.
As this is a breakout code, would it be possible to code in, that if the buy won, (say hit target) that the sell trade can’t happen and the other way, if the sell won, (say hit target) that the buy trade can’t happen.?
I can’t see anywhere in the guides anything about this, perhaps it’s not possible?
Thanks in advance. 😉
07/05/2018 at 10:19 AM #75275You can try this modified code: (not tested)
123456789101112131415161718192021222324252627282930313233343536defparam flatafter = 210000if longonmarket thenalreadybuy=1endifif shortonmarket thenalreadysell=1endifif intradaybarindex=0 thenalreadybuy=0alreadysell=0profit=strategyprofitendifif time = 061000 thenyh = highest[86](high)yL=lowest[86](low)os = 2*pipsizeendiftcondition = time>080000 and time<200000if tcondition and strategyprofit<=profit thenif close<yh+os and not alreadybuy thenbuy 1 contract at yh+os stopendifif close>yl+os and not alreadysell thensellshort 1 contract at yl-os stopendifendifset stop ploss 15set target pprofit 151 user thanked author for this post.
07/05/2018 at 11:03 AM #7528107/05/2018 at 11:43 AM #7529307/05/2018 at 12:03 PM #7530007/05/2018 at 12:07 PM #75302Because yl and yh are only calculated one time at 06h10 AM
To avoid the problem, try to change the code with:
123456789101112131415161718192021222324252627282930313233343536defparam flatafter = 210000if longonmarket thenalreadybuy=1endifif shortonmarket thenalreadysell=1endifif intradaybarindex=0 thenalreadybuy=0alreadysell=0myprofit=strategyprofitendifif time = 061000 thenyh = highest[86](high)yL=lowest[86](low)os = 2*pipsizeendiftcondition = time>080000 and time<200000if tcondition and strategyprofit<=myprofit and yh>0 and yl>0 thenif close<yh+os and not alreadybuy thenbuy 1 contract at yh+os stopendifif close>yl+os and not alreadysell thensellshort 1 contract at yl-os stopendifendifset stop ploss 15set target pprofit 1507/05/2018 at 1:39 PM #7532407/12/2018 at 8:06 AM #75840Nicholas / GraHal
Many thanks for the previous codes, they are working well, I am just a little lost with a trailing stop loss method. 😉
I have seen a stop loss method, as described below, and wondered if this was possible?
I looked through the https://www.prorealcode.com/blog/learning/kinds-trailing-stop-proorder/ but there are so many, I am confused as to which it could be. L
Original Target Profit in Pips = 100p
Projected Risk in Pips = -30pIn this scenario I would place a Hard Stop Loss @ Entry – 30p
Once the trade has acquired 50% of my Projected Profit {50p}, I will move my SL to risk 20% of those 50p.
50 x 20% = 10. Thereby Locking in a 40p Profit.And continue to Trail my SL @ Max Trade Profit Pips – (Max Trade Profit Pips x 20%)
I will continue to do this even through my Original Projected Profit in Pips Target of 100p
eg.
Up 50p = Risk 10p Locking in 40p Prft.
Up 80p = Risk 16p Locking in 64p Prft.
Up 100p = Risk 20p Locking in 80p Prft.
Up 135p = Risk 27p Locking in 108p Prft.
Up 200p = Risk 40p Locking in 160p Prft.Lastly, if I want to select which days of the week for a back-test, where do I insert the code please?
Say I would like to exclude Tuesday’s, but when I insert the code below in line 2, it doesn’t work.
DayOfWeek[1] DayOfWeek[3] DayOfWeek[4] DayOfWeek[5]
Monday =1
Tuesday =2
Wednesday =3
Thursday =4
Friday =5
Many thanks in advance.
07/12/2018 at 10:09 AM #75848As for SL, I think this should work fine (line 20 of the Snippet Library, modified to accomodate both Long & Short trades https://docs.google.com/spreadsheets/d/1rgboqj7sVwsP9ZRhOduOefye48QMWC07jWVXCl-KJPU/edit#gid=0)
Retain XX.X% profit123456789101112131415161718192021222324//////////////////////////////////////////////////////////////////////////////////////////////////////////ONCE TrailStart = 30 //30 Start trailing profits from this pointONCE ProfitPerCent = 0.666 //66.6% Profit to keepIF Not OnMarket THENy1 = 0y2 = 0ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (close - tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if 30+ pipsy1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFIF y1 THEN //Place pending STOP order when y>0SELL AT Tradeprice + (y1 * pipsize) STOP //convert pips to priceENDIFELSIF ShortOnMarket AND close < (TradePrice - (y2 * pipsize)) THEN //SHORTx2 = (tradeprice - close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN //go ahead only if 30+ pipsy2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFIF y2 THEN //Place pending STOP order when y>0EXITSHORT AT Tradeprice - (y2 * pipsize) STOP //convert pips to priceENDIFENDIF//////////////////////////////////////////////////////////////////////////////////////////////////////////As for DayOfWeek, lines 17 and 24 at https://www.prorealcode.com/topic/something-is-missing-in-my-friday-sell-off/ will be great of help.
3 users thanked author for this post.
07/12/2018 at 11:12 AM #75859Many thanks.
I have inserted the hard stop at: set stop ploss 30 and it works great. 🙂
I have looked at: (As for DayOfWeek, lines 17 and 24 at https://www.prorealcode.com/topic/something-is-missing-in-my-friday-sell-off/) but not being code minded, i’ll admit to being totally lost and all I get is an error message;
Syntax error:
This variable is not used in the code:daysforbiddenentry.
I tried to insert it here, I would like Tuesdays removed.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556defparam flatafter = 210000daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 2 OR OpenDayOfWeek = 3 OR OpenDayOfWeek = 4 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0if longonmarket thenalreadybuy=1endifif shortonmarket thenalreadysell=1endifif intradaybarindex=0 thenalreadybuy=0alreadysell=0endifif time = 061000 thenyh = highest[86](high)yL=lowest[86](low)os = 2*pipsizeendiftcondition = time>080000 and time<200000if tcondition thenif close<yh+os and not alreadybuy thenbuy 1 contract at yh+os stopendifif close>yl+os and not alreadysell thensellshort 1 contract at yl-os stopendifendifset stop ploss 30ONCE TrailStart = 30 //30 Start trailing profits from this pointONCE ProfitPerCent = 0.666 //66.6% Profit to keepIF Not OnMarket THENy1 = 0y2 = 0ELSIF LongOnMarket AND close > (TradePrice + (y1 * pipsize)) THEN //LONGx1 = (close – tradeprice) / pipsize //convert price to pipsIF x1 >= TrailStart THEN //go ahead only if 30+ pipsy1 = max(x1 * ProfitPerCent, y1) //y = % of max profitENDIFIF y1 THEN //Place pending STOP order when y>0SELL AT Tradeprice + (y1 * pipsize) STOP //convert pips to priceENDIFELSIF ShortOnMarket AND close < (TradePrice – (y2 * pipsize)) THEN //SHORTx2 = (tradeprice – close) / pipsize //convert price to pipsIF x2 >= TrailStart THEN //go ahead only if 30+ pipsy2 = max(x2 * ProfitPerCent, y2) //y = % of max profitENDIFIF y2 THEN //Place pending STOP order when y>0EXITSHORT AT Tradeprice – (y2 * pipsize) STOP //convert pips to priceENDIFENDIFMany thanks in advance
07/12/2018 at 11:36 AM #75860I tried again, incorperating the daysForbiddenEntry into the tcondition, but still I get the error.
12345678910IF tcondition = time>060500 and time<193000 and daysForbiddenEntry thenif tcondition and strategyprofit<=myprofit and yh>0 and yl>0 thenif close<yh+os and not alreadybuy thenbuy 1 contract at yh+os stopendifif close>yl+os and not alreadysell thensellshort 1 contract at yl-os stopendifendif07/12/2018 at 11:47 AM #75861To write code, please use the <> “insert PRT code” button to make code easier to read and understand. Thank you.
-
AuthorPosts