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 Mountain_cast, 02-10-2025, 11:14 PM
            3 responses
            20 views
            0 likes
            Last Post beobast
            by beobast
             
            Started by defa0009, 12-13-2024, 09:19 AM
            21 responses
            211 views
            1 like
            Last Post marcus2300  
            Started by ttrader23, Today, 04:48 PM
            0 responses
            8 views
            0 likes
            Last Post ttrader23  
            Started by wisdomspoon, Today, 03:50 PM
            3 responses
            16 views
            0 likes
            Last Post rockmanx00  
            Started by Robotman, Today, 01:06 PM
            2 responses
            37 views
            0 likes
            Last Post Robotman  
            Working...
            X