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 NullPointStrategies, Today, 05:17 AM
            0 responses
            52 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            130 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            70 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            43 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            47 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X