Codes for not opening trades at month end

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #175916 quote
    phanz
    Participant
    Average

    Hi,

    Is there a code that tell your algo not to open any trade at month end?  Month-end here will mean the last business day of the month and not the last day of the month.  Thank you.

    #175920 quote
    robertogozzi
    Moderator
    Master

    There you go (not tested):

    If OpenMonth <> OpenMonth[1] Then
       OM      = OpenMonth
       OD      = OpenDay
       ODW     = OpenDayOfWeek
       OY      = OpenYear
       LastDay = 31
       If OM = 4 or OM = 6 or OM = 9 or OM = 11 Then
          LastDay = 30
       Endif
       If OM = 2 Then
          LastDay = 28
          If OY mod 4 = 0 Then
             If OY mod 100 = 0 Then
                If OY mod 400 = 0 Then
                    LastDay = 29
                Endif
             Else
                LastDay = 29
             Endif
          Endif
       Endif
       EOM = OD      //EOM=End Of Month
       For i = OD + 1 To LastDay
          ODW = ODW + 1
          If ODW <= 5 Then
             EOM = i
          Elsif ODW = 7 Then
             ODW = 0
          Endif
       Next
    Endif
    //
    TradeON = 1
    If Day = EOM Then
       TradeON = 0
    Endif
    //
    If MyLongConditions And TradeON And Not OnMarket Then
       Buy 1 contract at Market
    Endif

    Use TradeON to enter a new trade.

    EOM only recognizes regular weekend days, not National, Bank, Labor holidays, etc…

    phanz and atxeel thanked this post
    #175921 quote
    phanz
    Participant
    Average

    Thanks Roberto!  I was just thinking maybe need to hard-code a set of specific dates to tell the algo not to trade on those dates but the algo that you have suggested is awesome!  Thank you!

    #175922 quote
    GraHal
    Participant
    Master

    Link to code above added as Log 303 here …

    Snippet Link Library

    robertogozzi and atxeel thanked this post
    #175928 quote
    robertogozzi
    Moderator
    Master

    Yes, you can certainly add any date not to be traded in addition to EOM.

    Usually holidays are known well before Jan. 1st.

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

Codes for not opening trades at month end


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
phanz @phanz Participant
Summary

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

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