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

GetDayBar - whats wrong

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

    #16
    Can you please post a screen-shot of the indicator applied, so I could recreate your exact FGBL chart here?

    Thanks,
    BertrandNinjaTrader Customer Service

    Comment


      #17
      Screenshot makes no sense, because my chart does not plot anything yet. At the moment it produces only debug output.

      Code:
      protected override void OnBarUpdate()
              {
                  // Use this method for calculating your indicator values. Assign a value to each
                  // plot below by replacing 'Close[0]' with your own formula.
                  // Plot0.Set(Close[0]);
                  double yesterdayRange = 0; 
                  
                  if ( PastCalculated == 0 ) {
                      if ( Bars.GetDayBar(1) != null )  {
                          //Print (" Prior Low " + Bars.GetDayBar(2).Low.ToString());
                          Print (" Prior Low GetDayBar(1) " + Bars.GetDayBar(1).Low.ToString());
                          Print (" Prior High GetDayBar(1) " + Bars.GetDayBar(1).High.ToString());
                             yesterdayRange = Bars.GetDayBar(1).High - Bars.GetDayBar(1).Low;
                             Print (" yesterdayRange: " + yesterdayRange.ToString());
                          
                          //Print (" Prior Low PriorDayOHLC " + PriorDayOHLC().PriorLow[0].ToString());
                          //Print (" Prior High PriorDayOHLC " + PriorDayOHLC().PriorHigh[0].ToString());
                      }
                      else  {
                          Print ("Yesterdays bar is null");
                          return;
                      }    
                      PastCalculated = 1;
                  }
                  
              }
      The output of this function is currently:
      Prior Low GetDayBar(1) 136,32
      Prior High GetDayBar(1) 137,26

      These values are valid for March 22, FGBL 06/12

      EDIT: In the properties of chart the number of days to load is set to 61. So March 22 = Today - 61 days. If I set the number of days to 90 Bars.GetDayBar(1) return values for 22. February
      Last edited by fel17; 05-22-2012, 11:47 AM.

      Comment


        #18
        Hello,

        I have tested your code and do not see the same behavior you are reported. using GetDayBar(1), I get the correct previous day.

        I'd suggest adding some Time[0] values to your Print() statements and also visually plotting the values to compare to the results we are getting on our end.

        Code:
            protected override void Initialize()
                {
                        Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                        Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "Plot1"));
                        Overlay                = true;
            
                }
        
                protected override void OnBarUpdate()
                {
                    
                double yesterdayRange = 0;
                    
                if ( PastCalculated == 0 ) {
                    if ( Bars.GetDayBar(1) != null )  {
                        
                        Plot0.Set(Bars.GetDayBar(1).Low);
                        Plot1.Set(Bars.GetDayBar(1).High);
                        //Print (" Prior Low " + Bars.GetDayBar(2).Low.ToString());
                        Print (Time[0] + "\t" + " Prior Low GetDayBar(1) " + Bars.GetDayBar(1).Low.ToString());
                        Print (Time[0] + "\t" + " Prior High GetDayBar(1) " + Bars.GetDayBar(1).High.ToString());
                        yesterdayRange = Bars.GetDayBar(1).High - Bars.GetDayBar(1).Low;
                        Print (Time[0] + "\t" + " yesterdayRange: " + yesterdayRange.ToString());
                        
                        //Print (" Prior Low PriorDayOHLC " + PriorDayOHLC().PriorLow[0].ToString());
                        //Print (" Prior High PriorDayOHLC " + PriorDayOHLC().PriorHigh[0].ToString());
                    }
                else  {
                    Print ("Yesterdays bar is null");
                    return;
                }    
                PastCalculated = 1;
                }
            
                }
            
                #region Properties
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries Plot0
                {
                    get { return Values[0]; }
                }
        
                [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                public DataSeries Plot1
                {
                    get { return Values[1]; }
                }
        Please let us know your results so we can compare on our end
        Attached Files
        MatthewNinjaTrader Product Management

        Comment


          #19
          Originally posted by NinjaTrader_Matthew View Post
          Hello,

          I have tested your code and do not see the same behavior you are reported. using GetDayBar(1), I get the correct previous day.
          Last week I made my first tests with getting historical data with GetDayBar(). This worked fine and I received correct values. If we forget null values, which are not predictable, imho. It looks like your test is like mine, 5 days before.

          Anyway, I guess the result of GetDayBar() depends on some properties of chart or maybe historical data on hdd. Or something else?

          I could of course add some Print() outputs to my debug, but I'm not sure whether this resolves my problem. The fact is: I get the values of first day in the chart. No kidding.

          Maybe you have another idea what to do? This is really a show stopper.

          P.S. Of course I could check with GetDayBar().Time the date of (1) but it makes the code more complex and less readable

          Comment


            #20
            Yes, it will depend on the property of the chart, such as the Session Template that was used the the number of days you have to load.

            I think I see what's going on - PastCalculated is not being reset to 0 after the script runs - where exactly are you declaring PastCalculated = 0 ? Please try resetting this to 0 either before or after this block of code in OnBarUpdate() and it should continue to run for each day on the chart.
            MatthewNinjaTrader Product Management

            Comment


              #21
              Originally posted by NinjaTrader_Matthew View Post
              Yes, it will depend on the property of the chart, such as the Session Template that was used the the number of days you have to load.

              I think I see what's going on - PastCalculated is not being reset to 0 after the script runs - where exactly are you declaring PastCalculated = 0 ? Please try resetting this to 0 either before or after this block of code in OnBarUpdate() and it should continue to run for each day on the chart.
              PastCalculated is set to 0 in Initialize(). I didn't paste this function into my code, but it is sure. PastCalculated isn't problem.

              Code:
                      protected override void Initialize()
                      {
                         // Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "Plot0"));
                          Overlay                = true;
                          CalculateOnBarClose = false;
                          PastCalculated = 0;
                      }
              The number of days to load is also not the point. I can load 5 or 60 or 90 days, but there are always significantly more the 2 days. So the chart has always yesterday's data, not only for loading, but visible visible. I never switch to 5min or less time frame. 15 min chart has always enough data to show yesterday too...

              Just tested of FESX 50, 60 min - the same result. First day in the chart, not yesterday.

              I think the problem is in the internal code of GetDayBar().

              If I call this function, NT starts to build virtual daily bars. From left to right, from first day to today. During building of first day I can see in the 60 min FESX50 14 debug outputs "Yesterdays bar is null" of my indicator. 14 is exactly the number of trading hours for EUREX (8:00-22:00) where FESX and FGLB is traded.

              When the first day is processed NT starts to build the second day. For this second day is the first day = yesterday (which is already virtually build up), so GetDayBar(1) returns OHLC for this day.

              I hope you understood what I mean

              Comment


                #22
                We've rechecked but unfortunately just can't reproduce what you describe here - are you running off our latest NT7 R10 release? Which time zone is set on the PC used?

                To streamline things down, please see my attached sample and screenshot - please run the exact indicator on your FGBL 06-12 15 min chart using a custom range from May 21 (Mon) to today and let me know if you would not see the same outcome as on my screenshot. Those values plotted would be accessible from the first bar of Tuesday on, so at a timestamp of 8:15 local Eurex time for this chart interval.

                Thanks,
                Attached Files
                Last edited by NinjaTrader_Bertrand; 05-23-2012, 09:49 AM.
                BertrandNinjaTrader Customer Service

                Comment


                  #23
                  Bertrand, I have a little beginner's problem with your script. I try to create a new indicator (from scratch) and replace generated but basically empty body of this indicator with your code. Ok, compiling without problems, saving too, but I do not see this new indicator in the list of availables. I can't add them to the chart. What's wrong?

                  it would be interesting what you'll see tomorrow, because 3 days loaded is a short time span.

                  To your questions:

                  I've updated NT today from .8 to .10. No effect.
                  Time zone was -1 from real time, but the changing didn't help

                  To illustrate this problem I've attached a screenshot made one hour ago. You can see the code of indicator. I've added a new debug output for GetDayBar(1).Time as soon as first "not null" virtual bar is returned. I also set chart's time frame to 240min to reduce number of "Yesterdays bar is null" messages.

                  After this I've attached my indicator to FGBL 06-12 240 min and change "Days to load" property of the chart. Started with 90 days, then 60, 30, 15. Every time after changing of this property indicator has been recalculated and so you can see in debug outputs what my script understands under GetDayBar(1). It's always first day of the chart, not yesterday
                  23.02 = 90 days
                  26.03 = 60
                  23.04 = 30
                  08.05 = 15

                  .
                  Attached Files

                  Comment


                    #24
                    fel17, please just copy in my exact script under Documents\NinjaTrader 7\bin\Custom\Indicator

                    Open any indicator in your editor and hit F5 to compile.

                    You can then apply the scrip GetPriorVirtualBars to your FGBL chart to check the outcome.
                    BertrandNinjaTrader Customer Service

                    Comment


                      #25
                      Bertrand, thanks for support. Your indicator works like you described. Right plots, GetDayBar(1).Close is yesterday's close and GetDayBar(2) - the close of day before.

                      Fine, but it doesn't explain why my indicator has another behaviour, exactly GetDayBar(n) has another logic then yours. Even applied to the same chart (together with yours, no other indicators, default chart setting) it produces the same wrong debug output. First day of chart for GetDayBAr(1).

                      Maybe because my indi doen't plot anything? I don't have other ideas. Probably I'll give up
                      Attached Files

                      Comment


                        #26
                        Thanks for the feedback - this means you're one step further, as the 'flaw' basically would be found in the indicator logic used - my recommendation would be removing any custom coded in logic until you hit the values you would expect, first of all I would remove the PastCalculated parts to ensure without it or it's logic in the mix, you would get the desired output. Then add complexity as the bases are covered only...
                        BertrandNinjaTrader Customer Service

                        Comment


                          #27
                          Hi,

                          the prob is still unsolved. Computer scientist would say GetDayBar(1) isn't undecidable (or just a bug) . The return value depends on where NT7 at execution time is. When NT7 starts to calculate indicator GetDayBar(1) returns some day in the past. After calculating of whole chart it is hopefully yesterday, but I can't code what I need if GetDayBar(1) isn't yesterday in OnBarUpdate().

                          Maybe last try: GetDayBar(1).Time would return the date of just meant by NT GetDayBar(1). I'd solve my problem, if I knew that it is previous trading day. I can't compare GetDayBar(1).Time with (Current_Date - 24h), because on monday it doesn't work correctly (previous day for monday is friday, not sunday). Also holidays... Previous trading session of last tuesday is also friday because of whitsun.

                          Any idea how to detect the date of previous trading day in the chart without using of GetDayBar(1)?

                          Comment


                            #28
                            GM fel17, from prior code snippets and examples we prepared for you, you can see the function itself returns just fine, thus we do not see where you would feel it's a bug coming into play here. Have you really stripped down your custom code to the bare essentials to rule out any issues stemming from this end? Also, on the first day of the chart the return would be null or nothing, as there is no prior data to build a virtual bar from.

                            Another way to access prior day data based on session template selected would be for example -

                            BertrandNinjaTrader Customer Service

                            Comment


                              #29
                              Bertrand, GetDayBar (1) returns virtual yesterday' values for just now draw virtual day bar. Double virtual. No way for serious coding.
                              Everyone expects on OnBarUpdate to be in the current bat, not in the (virtual) bar somewhere in the past.

                              Just create a simplest indicator with following code:

                              Code:
                                      protected override void OnBarUpdate()
                                      {
                                          // Use this method for calculating your indicator values. Assign a value to each
                                          // plot below by replacing 'Close[0]' with your own formula.
                                          if ( Bars.GetDayBar(1) != null )
                                              Print ("GetDayBar(1).Time: " + Bars.GetDayBar(1).Time.ToString() );            
                                          );  
                                      }
                              You will see in the output window all the days dates from chart history.

                              But, if I carefully read the description of the function GetDayBar I discover:

                              Definition
                              Returns a Bar object that represents a trading day whose properties for open, high, low, close, time and volume can be accessed. This bar is a virtual bar built off of the underlying data series. In some cases, the trading day bar can be used to represent a daily bar. Since this bar is virtual, its property values are calculated based on session definitions contained in the trading day only. This does not necessarily represent the actual day. You must check for a null reference since null is returned if there is insufficient intraday data to build a trading day bar.
                              Strictly seen, the function "works as designed". Not a bug, feature



                              The problem is: the is no way in NT to access reliably yesterday' or days before data. Not for the day in the past, but for today. OHLC values of the last day are very important for many strategies and signals. It's quite poor that NT don't provide them.


                              PriorDayOHLC works basically very similar to GetDayBar: it uses GetDayBar. Just add

                              Print("The prior session low value is " + PriorDayOHLC().PriorLow[0].ToString());

                              and you'll see all the lows in the history.



                              The solution for detecting of trading yesterday's date would probably workaround my problem.

                              Comment


                                #30
                                Originally posted by fel17 View Post
                                Bertrand, GetDayBar (1) returns virtual yesterday' values for just now draw virtual day bar. Double virtual. No way for serious coding.
                                Everyone expects on OnBarUpdate to be in the current bat, not in the (virtual) bar somewhere in the past.

                                Just create a simplest indicator with following code:

                                Code:
                                        protected override void OnBarUpdate()
                                        {
                                            // Use this method for calculating your indicator values. Assign a value to each
                                            // plot below by replacing 'Close[0]' with your own formula.
                                            if ( Bars.GetDayBar(1) != null )
                                                Print ("GetDayBar(1).Time: " + Bars.GetDayBar(1).Time.ToString() );            
                                            );  
                                        }
                                You will see in the output window all the days dates from chart history.

                                But, if I carefully read the description of the function GetDayBar I discover:


                                Strictly seen, the function "works as designed". Not a bug, feature



                                The problem is: the is no way in NT to access reliably yesterday' or days before data. Not for the day in the past, but for today. OHLC values of the last day are very important for many strategies and signals. It's quite poor that NT don't provide them.


                                PriorDayOHLC works basically very similar to GetDayBar: it uses GetDayBar. Just add

                                Print("The prior session low value is " + PriorDayOHLC().PriorLow[0].ToString());

                                and you'll see all the lows in the history.



                                The solution for detecting of trading yesterday's date would probably workaround my problem.
                                Given your code snippet, why would expect that you would not see data processed from every day on the chart? OnBarUpdate() is an event handler, which is triggered on all data in the stream that it processes. Without a specific escape statement, one would expect it to return values for all data in the stream that it processes. As with all stream data processing, each datum is sequentially the most current, as at when it is processed.

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by BarzTrading, Today, 07:25 AM
                                2 responses
                                24 views
                                1 like
                                Last Post BarzTrading  
                                Started by devatechnologies, 04-14-2024, 02:58 PM
                                3 responses
                                20 views
                                0 likes
                                Last Post NinjaTrader_BrandonH  
                                Started by tkaboris, Today, 08:01 AM
                                0 responses
                                4 views
                                0 likes
                                Last Post tkaboris  
                                Started by EB Worx, 04-04-2023, 02:34 AM
                                7 responses
                                163 views
                                0 likes
                                Last Post VFI26
                                by VFI26
                                 
                                Started by Mizzouman1, Today, 07:35 AM
                                1 response
                                10 views
                                0 likes
                                Last Post NinjaTrader_Gaby  
                                Working...
                                X