Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
            1 response
            47 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by CarlTrading, 04-01-2026, 02:41 AM
            0 responses
            23 views
            0 likes
            Last Post CarlTrading  
            Started by CaptainJack, 03-31-2026, 11:44 PM
            0 responses
            33 views
            1 like
            Last Post CaptainJack  
            Started by CarlTrading, 03-30-2026, 11:51 AM
            0 responses
            50 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 03-30-2026, 11:48 AM
            0 responses
            42 views
            0 likes
            Last Post CarlTrading  
            Working...
            X