Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetDayBar - whats wrong

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

    GetDayBar - whats wrong

    Hi there,

    i´d like to add an requirement to my automated trading strategy.

    I like to add a filter - to trade only days, where the close of one day ago was higher then the close of two days ago.

    I tryed to implement it this way:

    protected override void OnBarUpdate()
    ....
    if ( Bars.GetDayBar(1).Close > Bars.GetDayBar(2).Close && the other requirements)

    before adding this filter, everything worked fine. but after adding this filter i get the message:
    Error on calling 'OnBarUpdate' method for stratgy xy
    -when enableling the strategy.

    It would be great if you could give me a hint how to solve the problem.

    Thank You !

    #2
    GetDayBar() requires a null reference check/escape.

    Comment


      #3
      Hi Coganam,

      thank you that was easy.
      Here the new code for others who have the same problem:


      protected override void OnBarUpdate()
      ....
      if ( Bars.GetDayBar(1) != null && Bars.GetDayBar(2) != null && Bars.GetDayBar(1).Close > Bars.GetDayBar(2).Close && the other requirements)

      Thanx

      Comment


        #4
        I have a similar problem, so I try to ask in this thread.

        I need history of last 20 days which is queried by GetDayBar (1/2/.../20). The "Days to load" property of the chart is set to 60 - enough for my purposes. The chart itself has 15 or 30 minutes time frame. In the properties of indicator I set "Maximum bars to look back" on infinite.
        But I still can't access days 18, 19 and 20. GetDayBar(18 to 20, sometimes already for 16 or 15) is null.

        How I can solve this problem?

        Comment


          #5
          fel17, are you working in a indicator or strategy here? Single or MultiSeries?

          Thanks,

          Comment


            #6
            Originally posted by fel17 View Post
            I have a similar problem, so I try to ask in this thread.

            I need history of last 20 days which is queried by GetDayBar (1/2/.../20). The "Days to load" property of the chart is set to 60 - enough for my purposes. The chart itself has 15 or 30 minutes time frame. In the properties of indicator I set "Maximum bars to look back" on infinite.
            But I still can't access days 18, 19 and 20. GetDayBar(18 to 20, sometimes already for 16 or 15) is null.

            How I can solve this problem?
            Check your chart to be sure that enough days have been actually loaded. It is not what you ask to load that matters; it is what is actually loaded.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              fel17, are you working in a indicator or strategy here? Single or MultiSeries?
              Indicator. I don't know what MultiSeries are, I assume I'm working with Single series. I have only one "Value" in one time frame. Basically the easiest case. I also have 3-4 other indicators (provided by NT), but I don't think they disturb my indicator.

              Now I have this problem even with GetDayBar (1). I can see in my 15 minutes frame complete yesterday, but GetDayBar(1) = null

              Generally, GetDayBar seems to be very instable (buggy?) and uncomfortable for programming. I know, I have to check for NULL value, but what can I do if GetDayBar IS null? How I can force loading of enough history thru coding?
              Unfortunately there is no alternative to GetDayBar, besides of PriorDayOHLC which works only for prior day.

              Comment


                #8
                Unfortunately there would be supported way to force a loading of the data through code - as koganam advised please double check the chart contains the data you for the complete session you wish to access / build on with the virtual GetDayBar.

                For testing, I've attached a simple test indicator for you that work just fine on my ES 06-12 15 min charts running here on 'instrument default' sessions, so the CME US Index Futures ETH / Globex hours.

                If there was an issue loading your data from the provider connected to, right click on the chart and select 'Reload Historical Data'.

                Thanks,
                Attached Files

                Comment


                  #9
                  Thanks for example Bertrand.

                  I still do not understand how to load last days and I think this function is a little bit buggy. I've found a workaround: in OnBarUpdate() I return as long GetDayBar(1) is null. I can see in debug output that after 10-20 such returns Day(1) will be loaded and I can query the OHLC values.

                  Ok, but now I have another problem.
                  tradingDaysBars in Bars.GetDayBar(int tradingDaysBack) means the number of days back. So GetDayBar(1) = yesterday.
                  But the real behaviour is different. GetDayBar(1)means first day in the chart, not yesterday! I've checked values and this is definitely true. I have about two months loaded in the chart and I receive OHLC values from first day (two months ago). Is this a bug or feature?

                  Comment


                    #10
                    Thanks for the reply, so you would see the behavior you described with my example posted, is this correct? If so, which exact chart, timeframe, datafeed and session template + days loaded setting do yo use on your end?

                    Then I could attempt reproducing here to check into.

                    Thanks,

                    Comment


                      #11
                      I just looked your code, I did not run your indicator with real data.

                      Now I checked OHLC values for GetDayBar(2). High and Low are the same as for GetDayBar(1), but different in the chart. No clue...

                      Comment


                        #12
                        I would suggest giving the sample code prepared a run on your end and chart to doublecheck - you would also need to be mindful when exactly accessing the values and comparing, so Time[0] print + CurrentBar print is needed in debugging - if you plot / draw the results it would be more visual and thus likely easier.

                        Comment


                          #13
                          Just tell me what does GetDayBar(1) mean?
                          Yesterday or "depends on"?

                          Comment


                            #14
                            ...the previous trading session. Please see attached, ES 5 min running on RTH hours, highlighted is the previous session close level > compare to the plotted GetDayBar(1).Close in orange please for reference.
                            Attached Files

                            Comment


                              #15
                              Ok, I would also expect this behaviour. It corresponds to manual.

                              But in my case I get the values from the first day in the chart, which is 2 month ago. I can see these values if I scroll to the start of the chart.

                              I work with 15min chart for FGBL future, as example.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              605 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              351 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              560 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              561 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X