Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Reference Day of Week

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

    Reference Day of Week

    Hello & I hope someone can help:

    I want to find out what day of week it is today (monday, tuesday...) and then have my indicator do something.

    I read other posts using the "GetTradingDaysFromLocal" but in my case for some reason it works once when I compile the indicator, but afterwards it justs reference to the first day the chart start (so if I 5 days loaded it references to 5 days ago).

    This is what I have:

    if (CurrentBar == 0)
    {
    startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 30,0);


    currentDate = Bars.GetTradingDayFromLocal(Time[0]);

    return;
    }

    if (currentDate.DayOfWeek == DayOfWeek.Monday)
    {
    firstBars = GetBar(startDateTime.AddDays(-3));
    }


    DrawTextFixed("xx", "TEST-" + currentDate.ToString(), TextPosition.TopLeft, Color.Black, new Font("Arial Narrow", 12), Color.Crimson, Color.Red, 10);



    Check what today is, if monday then go back 3 days and do something. The DrawTextFixed I added to find out what is going on.

    Any hints would be appreciated.
    Martin

    #2
    Hello total3.

    The variable currentDate can only be set if CurrentBar is equal to 0.

    This means that the currentDate variable will only be set once on the first bar.

    What are you wanting to have happen?

    Why is this only being set on the first bar of historical data?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply,
      actually I want the first bar of the previous day's session and then do a calculation.

      I'm thinking now that it may be something along the lines of this, but it does not quite work. Is therer a different way to go about it ? Thank you.

      if (CurrentBar == 0)
      {
      startDateTime = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 9, 30, 0).AddDays(-1);
      }
      firstBars = GetBar(startDateTime);

      Comment


        #4
        Hello total3,

        If you would like to run code once on each session open use:

        if (Bars.FirstBarOfSession)
        {
        // execute code
        }

        http://www.ninjatrader.com/support/h...rofsession.htm
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you, I will try this!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X