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
-
-
07/27/2018 at 1:36 PM #7688607/27/2018 at 3:33 PM #76903
I think it should be (Barindex – TradeIndex) and not (TradeIndex – BarIndex) and it closes after 30 bars not 10.
I’m guessing you are on your phone Robertogozzi as the code was not inserted correctly – I tidied it up for you 🙂
I WAS on my phone (I also wrote TradeInex instead of TradeIndex, but on the phone I couldn’t see whether it was highlighted or not!) . Thank you Vonasi.
10/11/2018 at 2:13 PM #8255412345678910111213141516171819202122232425262728293031323334353637383940defparam 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*pipsizeendiftimeEnterBefore1 = time >= 080000timeEnterAfter1 = time < 120000timeEnterBefore2 = time >= 150000timeEnterAfter2 = time < 200000if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) thenif my condition 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 15I was trying to add 2 time conditions, but it doesn’t seem to be working.
Could somebody advise where I have gone wrong please?
10/11/2018 at 5:58 PM #82574There’s a missing ENDIF at line 37.
Also, testing MY CONDITION at line 29 is useless (but this does not affect performance) since it’s been already evaluated at line 27.
1 user thanked author for this post.
10/12/2018 at 4:18 PM #82657Robertogozzi,
Many thanks for your email reply. 😉
I added an, ENDIF in line 37, but the code doesn’t work?
I get a syntax error: the following variable is undefined : my condition.
Many thanks for all your help.
12345678910111213141516171819202122232425262728293031323334353637383940defparam 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*pipsizeendiftimeEnterBefore1 = time >= 080000timeEnterAfter1 = time < 120000timeEnterBefore2 = time >= 150000timeEnterAfter2 = time < 200000if my condition AND ((timeEnterBefore1 AND timeEnterAfter1) or (timeEnterBefore2 AND timeEnterAfter2)) thenif my condition 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 stopendifendifendifset stop ploss 15set target pprofit 1510/12/2018 at 5:12 PM #82664I thought MY CONDITION was a plain text to refer tou tour own undisclosed conditions.
Variable names cannot have spaces, nor special signs, only aphanumeric characters.
You will have to define what your conditions are and write them in palce of MY CONDITIONS, say
1Average[10,0](close) CROSSES OVER Average[50,0](close) //or CROSSES UNDER for short tradesor the like.
10/12/2018 at 5:22 PM #8266710/12/2018 at 5:26 PM #82670MYCONDITION, TCONDITION or whatever else you write MUST be defined before being used, if it refers to the time conditions already in place, just remove it.
10/15/2018 at 12:13 PM #82781Thank you, that made it work. 😉
10/18/2018 at 12:21 PM #83081Code didn't work the same.12345678910111213141516171819202122232425262728293031323334defparam flatafter = 210000if longonmarket thenalreadybuy=1endifif shortonmarket thenalreadysell=1endifif intradaybarindex=0 thenalreadybuy=0alreadysell=0myprofit=strategyprofitendifif time = 060500 thenyh = highest[85](high)yL=lowest[85](low)os = 3*pipsizeendiftcondition = time>074500 and time<205000if 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 15Hi,
Please could somebody clarify why my code works some days and not others.
On 5/10/18 my code worked, how I wanted it to work, 0805 it went short, after the breakout of the conditions, yl / yh.
On 8/10/18 my code didn’t work at 0755 short, when it should have, but activated at 1505n short? It’s the same code, the backtest proves it doesn’t work all the time.
I have experienced it on other days as well, sometimes it works and sometimes not, not sure why?
All I was after was a simple breakout strategy, but it seems I may have coded it incorrectly.
Many thanks in advance. (The code should be attached)
10/18/2018 at 1:13 PM #83093On which instrument and TF?
10/18/2018 at 1:20 PM #8309410/18/2018 at 2:08 PM #83100I think line 30 should read “close<yh-os“, but the cause for not entering on 8/10/18 at 0755 is because the previous bar, when the pending orders are placed, the short order was NOT place du to false conditions, because CLOSE (26435.1) < Y+OS(26435.6) and conditions at line 28 were not met.
1 user thanked author for this post.
10/18/2018 at 2:16 PM #83102You can use GRAPH to display variables at runtime, with their values retained each bar.
This debugging tool will help find out errors quickly (well… a bit quicker).
1 user thanked author for this post.
10/18/2018 at 2:42 PM #83105Many thanks again Roberto. 😉 I will have a look into the graph function.
I have changed the code, as you instructed above, it works on the 8/10/18, but there are more trades it does not take, where as the old code did.
I presume there is no way of re-wording my code, to simplify it, so when the price crosses the breakout points, yh / yl , it buys/sells regardless?
-
AuthorPosts
Find exclusive trading pro-tools on