Add & subtract time
Forums › ProRealTime English forum › ProOrder support › Add & subtract time
- This topic has 9 replies, 4 voices, and was last updated 5 years ago by
GraHal.
-
-
01/27/2020 at 11:23 PM #118095
Hello there folks,
I’m building a system that uses predefined time periods to enter trades. The time periods are derived from a single figure (i.e. 083000) combined with a number of minutes before and after the original figure to give a time zone where Pro Order is allowed to enter. For example, with an 8-minute buffer on either side, an original time of 083000 becomes an allowable trading zone that begins at 082200 and ends at 083800. I am manually typing a middle value for each trade, and then trying to automatically spread an entry range either side of it.
The code I have added here creates the zone correctly most of the time using the top variables “beforetime” and “aftertime”, but when it tries to add from a time that is towards the end of the hour, i.e. 085600, it understandably fails to come up with the right time of 090400.
085600 +
000800 (8 minutes) =
086400 (which obviously isn’t a real bar time because there is never a 64th minute in an hour!)
Although I know it is possible for me to work around this by telling Pro Order to only enter each trade between a time range (i.e. between 085600 and 090400), unfortunately this is no good for my backtesting. I want to quickly be able to answer the question of “what would my profit have been last week if I increased the range from the middle figure to be +16minutes and -16minutes?” I need some way of finding the optimum width of my allowed trading zones without retyping every single entry and exit time.
Does anyone know how I could do this?
Thank you in advance…
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071DEFPARAM CumulateOrders = Falsebreathing=16beforetime= 000800aftertime= 000800longentry1= close crosses over SuperTrend[1.5,34]shortentry1= close crosses under SuperTrend[1.5,34]longexit1= close crosses under SuperTrend[1.5,34]shortexit1= close crosses over SuperTrend[1.5,34]wedtime1=002000wedtime2=065800wedtime3=081800wedtime4=095400wedtime5=151200wedtime6=183600wedtime7=220800wedtime8=0wednesday=0wed1start = wedtime1 - beforetimewed1end = wedtime1 + aftertimewed2start = wedtime2 - beforetimewed2end = wedtime2 + aftertimewed3start = wedtime3 - beforetimewed3end = wedtime3 + aftertimewed4start = wedtime4 - beforetimewed4end = wedtime4 + aftertimewed5start = wedtime5 - beforetimewed5end = wedtime5 + aftertimewed6start = wedtime6 - beforetimewed6end = wedtime6 + aftertimewed7start = wedtime7 - beforetimewed7end = wedtime7 + aftertimewed8start = wedtime8 - beforetimewed8end = wedtime8 + aftertimeif time >=wed1start and time <=wed1end or time >=wed2start and time <=wed2end or time >=wed3start and time <=wed3end or time >=wed4start and time <=wed4end or time >=wed5start and time <=wed5end or time >=wed6start and time <=wed6end or time >=wed7start and time <=wed7end or time >=wed8start and time <=wed8end thenwednesday = 1endifIf longentry1 and wednesday =1 and opendayofweek=3 thenBUY 1 PERPOINT AT MARKETwednesday =0ENDIFIf shortentry1 and wednesday =1 and opendayofweek=3 thenSellshort 1 PERPOINT AT MARKETwednesday =0ENDIFif longonmarket and longexit1 and close > tradeprice thensell at close stopendifif longonmarket and longexit1 and close <= tradeprice thensell at tradeprice - breathing stopendifif shortonmarket and shortexit1 and close < tradeprice thenexitshort at close stopendifif shortonmarket and shortexit1 and close >= tradeprice thenexitshort at tradeprice + breathing stopendif01/28/2020 at 10:51 AM #11811401/28/2020 at 12:22 PM #118124Thanks for the response.
No, I haven’t tried doing that. What syntax would I need in order to capture “4th digit from right” in a six-digit number?
01/28/2020 at 12:32 PM #118125I tried the same using hours/minutes to let stop/limit orders run a certain time in the future using a timeframe retrieval snippet from Nicolas & Vonasi, which then is possible to optimise with factor x .
The problem occurred when reaching the end of the hour or let’s say the end of the day. I thought time would be more robust then bars because sometimes there are no bars when going to lower timeframes or have an instrument with low volatility.
Anyway I settled with bars. So x bars after the bar I specify (and before). Have a look at the programming guide prorealtime on p11.
Still i’am curious if you find a way for your approach!
01/28/2020 at 12:46 PM #118130What syntax would I need in order to capture “4th digit from right” in a six-digit number?
Off the top of my head, no idea if / how it would work, but I was thinking somehow using …
Time = 6R5R4R3R2R1R
Might spark an idea in our resident coding wizards minds? 🙂
01/28/2020 at 12:56 PM #11813601/28/2020 at 8:21 PM #118176time is simply HH MM and SS.
Then if we add a period of time on – for example HH=22 and we add 8 hours we get HH=30.
Then we say that if HH>24 then HH=HH-24 which will mean HH=6.
We also need to check if HH=24 and change it to HH=00 if it does.
We then reassemble our HH MM and SS to get our new time value.
1 user thanked author for this post.
01/28/2020 at 8:27 PM #118177Here is how to break time down to HH MM and SS
123456hhmmss = opentimehhmm00 = max(0,(round((opentime/100)-0.5))*100)hh0000 = max(0,(round((opentime/10000)-0.5))*10000)ss = hhmmss - hhmm00mm = (hhmmss - hh0000 - ss)/100hh = hh0000/100003 users thanked author for this post.
01/29/2020 at 11:28 AM #118197Thanks for the suggestion, but I’m struggling to understand how to incorporate it into my current code. At the moment I have eight instances of time that I manually input (eventually this will be for every day of the week, so there will be 40). Do I need to copy your code and replace “opentime” with each instance of my manually inputted time, i.e. wedtime2=065800?
Sample day of 8 time periods12345678910111213141516171819202122232425wedtime1=002000wedtime2=065800wedtime3=081800wedtime4=095400wedtime5=151200wedtime6=183600wedtime7=220800wedtime8=0wednesday=0wed1start = wedtime1 - beforetimewed1end = wedtime1 + aftertimewed2start = wedtime2 - beforetimewed2end = wedtime2 + aftertimewed3start = wedtime3 - beforetimewed3end = wedtime3 + aftertimewed4start = wedtime4 - beforetimewed4end = wedtime4 + aftertimewed5start = wedtime5 - beforetimewed5end = wedtime5 + aftertimewed6start = wedtime6 - beforetimewed6end = wedtime6 + aftertimewed7start = wedtime7 - beforetimewed7end = wedtime7 + aftertimewed8start = wedtime8 - beforetime01/29/2020 at 11:36 AM #118198Vonasi time breakdown added as Log 197 here …
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on