unknown specific day in the month

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #228076 quote
    MaoRai54
    Participant
    Master

    Hi everybody,

    after the big short candle of today due to the CPI data, I’d like to add in my strategies some lines to avoid any new trade in the period around the news.

    For Jobless data it’s easy because the news is always on Thursday all weeks.

    But for other news (Payrolls or CPI or RetailSales) that are, for example, only on the 2nd Tuesday of the month what do I have to write?

    Which are the instructions to let it know to avoid ONLY the second Tuesday ?

    Many thanks for your help

    #228080 quote
    PeterSt
    Participant
    Master

    Hi MaoRai,

    You could make some sort of loop which traces backwards (to) the 1st day of the month (Month <> Month[1]) and then looks forward for the 2nd Tuesday, starting 1 day further than what you found tracing backwards.
    More easy could be to just hard code the dates (see below for a list already there – you can extend it yourself of course).

    Regards,
    Peter

    MaoRai54 thanked this post
    image_2024-02-13_165429072.png image_2024-02-13_165429072.png
    #228082 quote
    MaoRai54
    Participant
    Master

    Hi,

    many thanks for your prompt reply.

    I’m unable to write the loop. I hope at Roberto or Nicolas will help me in that.

    Where did you get the sheet with the various dates of news ?

    #228084 quote
    PeterSt
    Participant
    Master
    #228092 quote
    Iván González
    Moderator
    Master

    Hi
    You could calculate wich tuesday it is with this code:

    if month = month[1] and dayofweek=2 then
    numtuesday = 1 + numtuesday
    elsif month = month[1] and dayofweek<>2 then
    numtuesday = numtuesday
    else
    numtuesday = 0
    endif 
    #228096 quote
    PeterSt
    Participant
    Master

    I shall be honest … I have been trying for 45 minutes or so, and couldn’t do it in that time.
    Then I saw your post, Iván, tried that, but unfortunately that doesn’t do a job either. Now 15 minutes later with your code as a base, I am going to give up and have a beer instead. 😜

    To let it work, (please) show a fully working snippet and point (Graph) at the 2nd Tuesdays of the month. Do you need a TimeFrame command, then inject that too.

    A strange beast this is !

    #228097 quote
    MaoRai54
    Participant
    Master

    Hi Ivan,

    thanks for your code but I don’t think it’s my request.

    I need a code that:

    • if the dayofweek=2 and (it is the second Tuesday of the month) and (hour=>14 and hour<=15) THENNoTrade=1

      Else

      NoTrade=0

      ENDIF

    • // where notrade=1 means not opening any trade in that day and hours
    #228106 quote
    JC_Bywan
    Moderator
    Master

    Hi,

    if opendayofweek=2 and openday>=8 and openday<=14 and openhour=14 then
     notrade=1
    else
     notrade=0
    endif
    
    return notrade
    MaoRai54 thanked this post
    #228109 quote
    JC_Bywan
    Moderator
    Master

    Sorry, for the hourly part I looked at it as not trading for one hour between 14h and 15h, but it seems you actually meant for 2 hours, not one. Although depending if you used hour in its PRT meaning of candle closing time, or as a word, I am not sure if you meant no trade between 13h and 15h, or between 14h and 16h.

    If from 13h to 15h, please replace “and openhour=14 then” in line 1 by “and (openhour=13 or openhour=14) then

    If from 14h to 16h, please replace “and openhour=14 then” in line 1 by “and (openhour=14 or openhour=15) then

    PeterSt thanked this post
    #228118 quote
    PeterSt
    Participant
    Master

    Hi JC – I am sure this is perfect. Very well done. No trading in the hour of PCI data (which comes in at 15:30).
    For MaoRai : don’t forget about the Daylight Savings difference between Europe (the area you imply) and the USA (which designates the PCI report at 08:30).

    image_2024-02-14_043241334.png image_2024-02-14_043241334.png image_2024-02-14_043905053.png image_2024-02-14_043905053.png
    #228121 quote
    PeterSt
    Participant
    Master

    Just in case, about the Daylight Saving :

    DLS = 0   // 0 = Normal. 1 = Autumn. 2 = Spring.
    
    If Date >= 20221031 and Date <= 20221104 then
      DLS = 1   // Autumn. USA is one hour early.
    elsif Date >= 20230312 and Date <= 20230326 then
      DLS = 2   // Spring. USA is one hour early.
    endif  
      
    // Justadd a group for convenience (no difficult If/Else stuff). 
    // And the above can even be used for more history backtesting.
    
    If Date >= 20231029 and Date <= 20231105 then
      DLS = 1   // Autumn. USA is one hour early.
    elsif Date >= 20240310 and Date <= 20240331 then
      DLS = 2   // Spring. USA is one hour early.
    endif  
    
    #228132 quote
    PeterSt
    Participant
    Master

    No trading in the hour of PCI data (which comes in at 15:30).

    No PeterSt … that is 14:30.

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

unknown specific day in the month


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
MaoRai54 @maorai Participant
Summary

This topic contains 11 replies,
has 4 voices, and was last updated by PeterSt
2 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/13/2024
Status: Active
Attachments: 3 files
Logo Logo
Loading...