Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Strategy analyzer doesn't "see" last bar of day?

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

    Strategy analyzer doesn't "see" last bar of day?

    I've noticed that the strategy analyzer will ignore bars at the end of the day. How can this be fixed? I'm surprised this hasn't been reported before, so I am including a stripped down example so you can recreate on your end.

    I've attached data from stock ABCD. The data should be imported using Format = NinjaTrader (beginning of bar timestamps), DataType = Last, Time Zone= Eastern Time (US and Canada).

    I've pasted the most basic strategy below that just prints to the output screen the Time and current Close of the instrument:

    Code:
    namespace NinjaTrader.NinjaScript.Strategies
    {
    	public class Test2: Strategy
    	{
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				Description									= @"Enter the description for your new custom Strategy here.";
    				Name										= "Test2";
    				Calculate									= Calculate.OnBarClose;
    				EntryHandling								= EntryHandling.AllEntries;
    				IsExitOnSessionCloseStrategy				= true;
    				
    			}
    		}
    
    		protected override void OnBarUpdate()
    		{			
    			Print(Time[0] + "     " + Closes[0][0] );
    		}
    	}
    }
    Run the strategy analyzer on ABCD with the following parameters:
    Start Date: 08/01/2014
    End Date: 08/05/2014
    Trading Hours: Default 24/7
    Break at EOD: yes

    Then look at the last few lines of the output:

    8/4/2014 3:43:00 PM 396.35
    8/4/2014 3:44:00 PM 396.25
    8/4/2014 3:45:00 PM 396.2
    8/4/2014 3:46:00 PM 396.05
    8/4/2014 3:47:00 PM 396.05
    8/4/2014 3:48:00 PM 396
    8/4/2014 3:49:00 PM 395.95
    8/4/2014 3:51:00 PM 395.95
    8/4/2014 3:52:00 PM 395.95
    8/4/2014 3:53:00 PM 395.95
    8/4/2014 3:54:00 PM 395.95
    8/4/2014 3:55:00 PM 395.9
    8/4/2014 3:56:00 PM 395.8
    8/4/2014 3:57:00 PM 395.7
    8/4/2014 3:58:00 PM 395.7
    8/4/2014 3:59:00 PM 395.65
    in State.SetDefaults
    in State.Terminated

    The strategy is not able to "see" the bar on 8/4/2014 4:00:00, which is 395.60. It thinks the end of the day is 3:59:00 PM even though I've set it for default 24/7.
    Attached Files

    #2
    Hello YD777,
    Thanks for your post.

    I have taken a look at your attached historical data file and it appears that there is not any more historical data on 08/04/2014 beyond 3:59PM.

    20140804 155900; 395.7000; 395.8500; 395.6000; 395.6000; 17
    20140805 020000; 395.2000; 395.4000; 394.9500; 395.1000; 149
    Please let me know if you have any further questions.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Josh, please look at the last line for 8/14 in the data file. The close value for the last bar should be 395.60. This is for the bar starting at 15:59 (which once loaded into NT would be the 16:00 bar).

      Again, as I said, NT is missing this last bar for 8/14 at 16:00. Instead the last bar the strategy acts on is the 15:59 bar (15:58 in the text file) with value 395.65.
      Last edited by YD777; 02-26-2018, 07:12 PM.

      Comment


        #4
        Hello YD777,
        Thanks for your note.

        When you imported the historical data did you ensure that you selected 'beginning of bar timestamps'? I initially imported using the 'end of bar timestamp' option. When I reimported using the 'beginning of bar' option I was able to view that bar.

        Import Options
        https://ninjatrader.com/support/help...gImportOptions

        I look forward to your reply.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          Thanks for the reply. Yes, I did use "beginning of bar" timestamps. I have no problem seeing the bar on a chart, the problem is that the strategy doesn't act on this bar.

          Please see my original question to see step by step what I do to recreate the problem (e.g. I already mentioned in the question that I import "beginning of bar"). I tried to include everything in that original question that you'll need to recreate the issue.

          Comment


            #6
            Hello YD777,

            The strategy is not processing that last bar because it has not closed and no bar opens past it. This is expected and is the nature of historical bar processing as OnBarUpdate() will only be called when a new bar begins to process. The frequency in which OnBarUpdate() is called will be determined by the "Calculate" property so if you set "Calculate" to "OnEachTick" the Strategy Analyzer will be able to see that last bar.

            OnBarUpdate()
            https://ninjatrader.com/support/help...nbarupdate.htm

            Calculate
            https://ninjatrader.com/support/help...?calculate.htm

            If you wanted to specifically do something on the last bar you will need to include that in your logic. You could use IsLastBarOfSession to identify if the current processing bar is the last bar updated in a trading session. Something like the following snippet would identify the 4:00PM bar for you.
            Code:
            protected override void OnBarUpdate()
            {
                 if ( Bars.IsLastBarOfSession )
            }
            IsLastBarOfSession
            https://ninjatrader.com/support/help...rofsession.htm

            Please let me know if you have any further questions.
            Josh G.NinjaTrader Customer Service

            Comment


              #7
              Great, thanks. Now it makes sense

              Comment


                #8
                Originally posted by NinjaTrader_JoshG View Post
                The strategy is not processing that last bar because it has not closed and no bar opens past it. This is expected and is the nature of historical bar processing as OnBarUpdate() will only be called when a new bar begins to process.
                Thanks again Josh. However, now I'm finding situations where the above behavior does NOT occur. I started a new thread because it seems to be a bigger issue/bug.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by sidlercom80, 10-28-2023, 08:49 AM
                168 responses
                2,262 views
                0 likes
                Last Post sidlercom80  
                Started by Barry Milan, Yesterday, 10:35 PM
                3 responses
                10 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by WeyldFalcon, 12-10-2020, 06:48 PM
                14 responses
                1,429 views
                0 likes
                Last Post Handclap0241  
                Started by DJ888, 04-16-2024, 06:09 PM
                2 responses
                9 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by jeronymite, 04-12-2024, 04:26 PM
                3 responses
                41 views
                0 likes
                Last Post jeronymite  
                Working...
                X