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 CarlTrading, 03-31-2026, 09:41 PM
          1 response
          156 views
          1 like
          Last Post NinjaTrader_ChelseaB  
          Started by CarlTrading, 04-01-2026, 02:41 AM
          0 responses
          90 views
          1 like
          Last Post CarlTrading  
          Started by CaptainJack, 03-31-2026, 11:44 PM
          0 responses
          140 views
          2 likes
          Last Post CaptainJack  
          Started by CarlTrading, 03-30-2026, 11:51 AM
          0 responses
          130 views
          1 like
          Last Post CarlTrading  
          Started by CarlTrading, 03-30-2026, 11:48 AM
          0 responses
          107 views
          0 likes
          Last Post CarlTrading  
          Working...
          X