Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

2nd trading day of month

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    2nd trading day of month

    Hi,
    How would you define, in ninjascript, the 2nd trading day of a given month?
    thanks,
    David

    #2
    I'm thinkiing of a counter using:

    bool tradingDayCounter;


    e = Times[0][0].Month;

    bool Condition1 = false;

    Condition1 = e != prevMonth;

    myDate = Times[0][0];

    if (IsTradingDayDefined(myDate) && Condition1 == true)
    tradingDayCounter ++

    If (tradingDayCounter == 2)
    do stuff

    Am i on the right track?

    ​

    Comment


      #3
      Hello trader3000a,

      The Trading hours should only load actual trading days in the data, so I would not imagine a sessioniterator would be necessary.

      Using a counter would be effective.

      Code:
      private int previousMonth, tradingDays;
      
      if (Bars.IsFirstBarOfSession)
      {
          if (previousMonth != Time[0].Month)
          {
              previousMonth = Time[0].Month;
              tradingDays = 0;
          }
      
          tradingDays++;
      
          Print(Time[0]);
      
          if (tradingDays == 2)
              Print(string.Format("Day of month: {0}", Time[0].Day));
      }
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi Chelsea,
        I really appreciate your help with this. It works great on minute charts, but I can't get any output from it on a daily chart. I'm guessing there's an adjsutment I need to make with "IsFirstBarOfSession" to get it going on daily bars? I guess just leave that part out?
        David
        Last edited by trader3000a; 07-05-2023, 09:49 AM.

        Comment


          #5
          Hello David,

          Yes, Bars.IsFirstBarOfSession is false on day bars. Leave that part out.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Nice. thanks again!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Segwin, 05-07-2018, 02:15 PM
            14 responses
            1,789 views
            0 likes
            Last Post aligator  
            Started by Jimmyk, 01-26-2018, 05:19 AM
            6 responses
            837 views
            0 likes
            Last Post emuns
            by emuns
             
            Started by jxs_xrj, 01-12-2020, 09:49 AM
            6 responses
            3,293 views
            1 like
            Last Post jgualdronc  
            Started by Touch-Ups, Today, 10:36 AM
            0 responses
            13 views
            0 likes
            Last Post Touch-Ups  
            Started by geddyisodin, 04-25-2024, 05:20 AM
            11 responses
            63 views
            0 likes
            Last Post halgo_boulder  
            Working...
            X