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 jxs_xrj, 01-12-2020, 09:49 AM
    6 responses
    3,290 views
    1 like
    Last Post jgualdronc  
    Started by Touch-Ups, Today, 10:36 AM
    0 responses
    7 views
    0 likes
    Last Post Touch-Ups  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    61 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    8 views
    0 likes
    Last Post Option Whisperer  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    24 views
    0 likes
    Last Post halgo_boulder  
    Working...
    X