Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsFirstBarOfSession Workaround

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

    IsFirstBarOfSession Workaround

    IsFirstBarOfSession not working in NT8 is there a recommended workaround?

    unsure about IsNewSession or if ok in NT8 or if IsFirstBarOfSession fix available?

    using 8.0.0.9 64-bit.

    Code:
    protected override void OnBarUpdate()
    {
      // Switch a bool named takeTrades to false when IsNewSession() returns true. 
      if (Bars.SessionIterator.IsNewSession(DateTime.Now, true)) ;
      {
          Alert("EOS", Priority.Medium, String.Format("New session beginning. Waiting until {0} to begin trading again"), " ", 5, Brushes.Black, Brushes.White);
          takeTrades = false;
      }
     
      // Set the bool back to true on the first bar of the new session
      if (Bars.IsFirstBarOfSession)
          takeTrades = true;
    }
    i.e how to detect 1st bar of session for chart interval 5,10,30 etc.)
    Last edited by delTik; 04-25-2016, 05:01 AM.

    #2
    Hello delTik,

    Thank you for your post.

    IsFirstBarOfSession is working in my install of NinjaTrader. Try using Print() to see if the Output shows the IsFirstBarOfSession as working.
    For example:
    Code:
    if (Bars.IsFirstBarOfSession)
    {
    Print("FirstBarOfSession: " + Time[0]);
    takeTrades = true;
    }
    You would open the Output window under New > NinjaScript Output.

    For the SessionIterator you would need to create a new one and use Time[0] as DateTime.Now will be the local PC time and you want to pull the bar's timestamp instead.
    For example:
    Code:
    		protected override void OnStateChange()
    		{
    			...
    			if (State == State.Historical)
    			{
    				//stores the sessions once bars are ready, but before OnBarUpdate is called
    				sessionIterator = new SessionIterator(Bars);
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{
    			//sessionIterator.GetNextSession(Time[0], true);
    		}
    For more information please visit the following link: http://ninjatrader.com/support/helpG...oniterator.htm

    Please let me know if you have any questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Shansen, 08-30-2019, 10:18 PM
    24 responses
    938 views
    0 likes
    Last Post spwizard  
    Started by Max238, Today, 01:28 AM
    0 responses
    3 views
    0 likes
    Last Post Max238
    by Max238
     
    Started by rocketman7, Today, 01:00 AM
    0 responses
    2 views
    0 likes
    Last Post rocketman7  
    Started by wzgy0920, 04-20-2024, 06:09 PM
    2 responses
    27 views
    0 likes
    Last Post wzgy0920  
    Started by wzgy0920, 02-22-2024, 01:11 AM
    5 responses
    32 views
    0 likes
    Last Post wzgy0920  
    Working...
    X