Add & subtract time

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #118095 quote
    Mike Boorman
    Participant
    Average

    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…

    DEFPARAM CumulateOrders = False
    
    breathing=16
    beforetime= 000800
    aftertime= 000800
    
    longentry1= 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=002000
    wedtime2=065800
    wedtime3=081800
    wedtime4=095400
    wedtime5=151200
    wedtime6=183600
    wedtime7=220800
    wedtime8=0
    
    wednesday=0
    wed1start = wedtime1 - beforetime
    wed1end = wedtime1 + aftertime
    wed2start = wedtime2 - beforetime
    wed2end = wedtime2 + aftertime
    wed3start = wedtime3 - beforetime
    wed3end = wedtime3 + aftertime
    wed4start = wedtime4 - beforetime
    wed4end = wedtime4 + aftertime
    wed5start = wedtime5 - beforetime
    wed5end = wedtime5 + aftertime
    wed6start = wedtime6 - beforetime
    wed6end = wedtime6 + aftertime
    wed7start = wedtime7 - beforetime
    wed7end = wedtime7 + aftertime
    wed8start = wedtime8 - beforetime
    wed8end = wedtime8 + aftertime
    
    
    
    if 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 then
    wednesday = 1
    endif
    
    If longentry1 and wednesday =1 and opendayofweek=3 then
    BUY 1 PERPOINT AT MARKET
    wednesday =0
    ENDIF
    
    If shortentry1 and wednesday =1 and opendayofweek=3 then
    Sellshort 1 PERPOINT AT MARKET
    wednesday =0
    ENDIF
    
    
    if longonmarket and longexit1 and close > tradeprice then
    sell at close stop
    endif
    
    if longonmarket and longexit1 and close <= tradeprice then
    sell at tradeprice - breathing stop
    endif
    
    if shortonmarket and shortexit1 and close < tradeprice then
    exitshort at close stop
    endif
     
    if shortonmarket and shortexit1 and close >= tradeprice then
    exitshort at tradeprice + breathing stop
    endif
    #118114 quote
    GraHal
    Participant
    Master

    Did you try adding code to achieve something like …

    4R = 4th digit from right
    5R = 5th digit from right

    If 4R = 6 Then
    4R  = 0
    5R = 5R  + 1
    Endif

    #118124 quote
    Mike Boorman
    Participant
    Average

    Thanks 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?

    #118125 quote
    Paul
    Participant
    Master

    I 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!

    #118130 quote
    GraHal
    Participant
    Master

    What 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? 🙂

    #118136 quote
    GraHal
    Participant
    Master

    Above should read MyTime =  6R5R4R3R2R1R  (from your calcs / whatever you are calling the results of your calcs in your code).

    I say above as TIME (reserved word in PRT) could never get to 6 as a 4R digit etc.

    #118176 quote
    Vonasi
    Moderator
    Master

    time 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.

    Paul thanked this post
    #118177 quote
    Vonasi
    Moderator
    Master

    Here is how to break time down to HH MM and SS

    hhmmss = opentime
    hhmm00 = max(0,(round((opentime/100)-0.5))*100)
    hh0000 = max(0,(round((opentime/10000)-0.5))*10000)
    ss = hhmmss - hhmm00
    mm = (hhmmss - hh0000 - ss)/100
    hh = hh0000/10000
    Paul, Mike Boorman and nonetheless thanked this post
    #118197 quote
    Mike Boorman
    Participant
    Average

    Thanks 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?

    wedtime1=002000
    wedtime2=065800
    wedtime3=081800
    wedtime4=095400
    wedtime5=151200
    wedtime6=183600
    wedtime7=220800
    wedtime8=0
     
    wednesday=0
    wed1start = wedtime1 - beforetime
    wed1end = wedtime1 + aftertime
    wed2start = wedtime2 - beforetime
    wed2end = wedtime2 + aftertime
    wed3start = wedtime3 - beforetime
    wed3end = wedtime3 + aftertime
    wed4start = wedtime4 - beforetime
    wed4end = wedtime4 + aftertime
    wed5start = wedtime5 - beforetime
    wed5end = wedtime5 + aftertime
    wed6start = wedtime6 - beforetime
    wed6end = wedtime6 + aftertime
    wed7start = wedtime7 - beforetime
    wed7end = wedtime7 + aftertime
    wed8start = wedtime8 - beforetime
    #118198 quote
    GraHal
    Participant
    Master

    Vonasi time breakdown added as Log 197 here …

    Snippet Link Library

    Paul thanked this post
Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.

Add & subtract time


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 9 replies,
has 4 voices, and was last updated by GraHal
6 years, 1 month ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 01/27/2020
Status: Active
Attachments: No files
Logo Logo
Loading...