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 sjsj2732, Yesterday, 04:31 AM
          0 responses
          38 views
          0 likes
          Last Post sjsj2732  
          Started by NullPointStrategies, 03-13-2026, 05:17 AM
          0 responses
          287 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          288 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          134 views
          1 like
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          95 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Working...
          X