Code for trading day and time

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #175699 quote
    PierreD
    Participant
    New

    Hello I would like to know how to code to compare two candlestick of too different trading date and with a defined trading time :

    exemple

    how to compare the opening price of a 5 min candlestick the 2021 08 15 @ 10h30 and the closing price of a 5 min candlestick the 2021 07 15 @ 17h35
    I can’t find this in the compagny’s trading book exemples.

    Many thanks for your help

    Regards

    #175706 quote
    robertogozzi
    Moderator
    Master

    There’s no specific instruction, you need to store the current value  in a variable, then use FOR…NEXT to scan past candles until you find the desired one:

    IF OpenTime = 103000 AND OpenDate = 20210815 THEN
      MyOpen = open
      FOR i = 1 to Barindex
         IF OpenDate[i] = 20210715 AND OpenTime[i] = 173500 THEN
            MyClose = close[i]
            Break
         ENDIF
      NEXT
    ENDIF
    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums. I moved it from the French forum. Thank you 🙂
    #175710 quote
    PierreD
    Participant
    New
    Many thanks for your help and your reactivity best regards   Pierre
    #175843 quote
    PierreD
    Participant
    New
    Dear Mr Robertogozzi hello,   Once again thanks for your help Is it possible to get another help :   I would like to know if it’s possible for the function Opentime and Opendate to use a variable value : to be able in a backtest to optimize for exemple the best trading time and the best trading day for a trading system exemple I want to backtest this system :   I compare the opening price of a 5 minute candle today (it could be a variable as well to test 10 minutes 30 minutes, 1 minute…) @ 10h30 (for exemple but I would like to use a variable data to see if it’s better to compare the previous day @ 10 h30 o r 10h25 or 10h35 …) with the closing price of a contract the previous trading day @ 18h30 (for exemple but I would like to use a variable data to see if it’s better to compare the previous day @ 18 h30 o r 18h35 or 18h40 …) If it’s up, I buy a contrat and then I keep the position for a few hours, and I sell this osition of 1 contract later today @ 16h30 (for exemple but I would like to use a variable data to see if it’s better to keep the position later or sooner @ 16 h35 o r 16h40 or 15h30 or 15h35 …)   I would appreciate if you can help me on this code Many thanks for your time Best regards   Pierre
    #175866 quote
    robertogozzi
    Moderator
    Master
    Yes for both OpenTime and OpenDate, but as to OpenDate I can’t think of any situation where optimization could be of much use. For both of them you can replace numeric constants with a variable name of your choice to be used in optimization. For OPENTIME you can set a starting time, say 090000, an ending time, say 170000 and a step, say 010000 for 1 hour. I suggest that you always enter 6 digits and ignore if they are later dropped. OPENDATE requires 8 digits, instead.
    #175983 quote
    robertogozzi
    Moderator
    Master
    TIMEFRAME does not support variables, so you have to optimize it changing the TF manually. To compare any candle today with the previous at a given time you have to use a variable, then compare any subsequent candle with it:
    IF Time = 183000 THEN   //or OpenTime
       Time1830 = close
    ENDIF
    Then use Time1830 to be compared to other candles, it will change everyday at 183000 (you can optimize it as explained above).
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.

Code for trading day and time


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
PierreD @pierred Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by robertogozzi
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/19/2021
Status: Active
Attachments: No files
Logo Logo
Loading...