Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars.GetBar error, return wrong bar.

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

    Bars.GetBar error, return wrong bar.

    NT Version 8.0.0.11 (Multi-Broker) - BETA
    My time zone (UTC +3:00)

    Bars.GetBar return wrong bar.

    Defaults:
    Code:
    if (State == State.SetDefaults)
    			{
    				Description									= @"z";
    				Name										= "Development";
    
    				
    				Calculate									= Calculate.OnEachTick;
    				IsOverlay									= true;
    				IsAutoScale									= true;
    				DisplayInDataBox							= true;
    				DrawOnPricePanel							= true;
    				DrawHorizontalGridLines						= true;
    				DrawVerticalGridLines						= true;
    				PaintPriceMarkers							= true;
    				ScaleJustification							= NinjaTrader.Gui.Chart.ScaleJustification.Right;
    				MaximumBarsLookBack 						= MaximumBarsLookBack.Infinite;
    				
    				//Disable this property if your indicator requires custom values that cumulate with each new market data event. 
    				//See Help Guide for additional information.
    				IsSuspendedWhileInactive					= true;
    				AddPlot(new Stroke(Brushes.Red, 3), PlotStyle.Dot, "zzzzMax");
    				AddPlot(new Stroke(Brushes.Red, 3), PlotStyle.Dot, "zzzzMin");
    }
    onBarUpdate:
    Code:
    DateTime start = new DateTime(2016, 08, 10, 00, 00, 01);
    int bar = Bars.GetBar(start); <---------- wrong answer
    int barsAgo = CurrentBar - bar;
    My time zone (UTC +3:00)

    #2
    Hello nordseven,

    Thank you for writing in.

    I would first suggest updating to the latest beta, version 12. The download link for beta 12 can be found here: https://ninjatrader.com/support/help...n-us/?beta.htm

    Can you please explain what you are seeing from Bars.GetBar(start) that is giving you a wrong answer?

    As a test, I've opened a 1 minute ES 09-16 chart and used the logic below to verify if Bars.GetBar(start) is providing the correct absolute bar index:

    Code:
    DateTime start = new DateTime(2016, 8, 10, 00, 00, 01);
    if (CurrentBar == Bars.GetBar(start))
    {
    	Print(CurrentBar);
    	Print(Time[0]);
    }
    The print of Time[0] outputs 8/10/2016 12:01:00 as I expect from a minute bar (since it's grabbing the close time of the bar).
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Okay, i'm found where i have error.

      in NinjaTrader7:

      "Bars.Count" equals "CurrentBar"

      in NinjaTrader8:

      "Bars.Count" not equals "CurrentBar"

      "CurrentBar" equals the "Bar" where script(indicator) start execution.

      Comment


        #4
        Hello nordseven,

        I would like to note that there should never be an instance where Bars.Count equals CurrentBar.



        The CurrentBar value is guaranteed to be <= Count - 1. It will be Count - 1 if CalculateOnBarClose is set to false or Count - 2 if CalculateOnBarClose is set to true.

        I see this behavior replicated in both NinjaTrader 7 and NinjaTrader 8.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Okay, in NT7 maybe you right, CurrentBar = Bars.Count - 1; Suppose I slowly opened visual studio and bar counter has changed. But in NT8 this is work not like in NT7.

          I'm start my script from condition (in NT7 and NT8):

          DateTime today = new DateTime.Now;

          OnBarUpdate() {

          if (ToDay(Time[0]) == ToDay(today) && Bars.IsFirstBarOfSession && IsFirstTickOfBar ) {
          //in NT7 i have here CurrentBar == Bars.Count - 1;
          //in NT8 i have here CurrentBar == BarsCount - Bars.BarsSinceNewTradingDay // i mean CurrentBar equals FirstBarOfSession.
          }
          }

          Of course this is a simplified example, I have a 2-level nested functions, but everything starts from this condition.
          Last edited by nordseven; 08-11-2016, 04:12 PM.

          Comment


            #6
            Hello nordseven,

            The value of CurrentBar matches in both NinjaTrader 7 and NinjaTrader 8 with the logic you have provided.

            I had to modify the syntax for NinjaTrader 7

            Code:
            DateTime today = DateTime.Now;
            if (ToDay(Time[0]) == ToDay(today) && Bars.FirstBarOfSession && FirstTickOfBar)
            Please ensure that you are running on the exact same instrument with the exact same parameters for the chart's data series on both platforms.

            If you are not seeing the same CurrentBar value, please provide your NT7 and NT8 scripts.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              Hello NinjaTrader_ZacharyG.

              I can't give you my script, but when I have time, I will make for you a simple script for this and other error that I found today. Good luck!

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Jimmyk, 01-26-2018, 05:19 AM
              6 responses
              834 views
              0 likes
              Last Post emuns
              by emuns
               
              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
              10 views
              0 likes
              Last Post Touch-Ups  
              Started by geddyisodin, 04-25-2024, 05:20 AM
              11 responses
              62 views
              0 likes
              Last Post halgo_boulder  
              Started by Option Whisperer, Today, 09:55 AM
              0 responses
              8 views
              0 likes
              Last Post Option Whisperer  
              Working...
              X