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

Historical Property Always Return False (Revisited)

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

    Historical Property Always Return False (Revisited)

    I would like to re-raise an old issue (http://www.ninjatrader.com/support/forum/showthread.php?t=34488).

    In summary, in a strategy when a secondary daily series is added to an existing primary series (in this case a 5 minute series) two things occur. First, the historical property always returns false in the OnBarUpdate event, even on the historical bars where the property should be true. Second, the OnBarUpdate event is never fired for the historical bars of the secondary series.

    Please note that when the same code is run within an indicator then everything works as expected (my expectations anyway J). It is only within a strategy that these anomalies exist. Why is the behavior of the software different between an indicator and a strategy?

    I am running a fresh install of the most current version of the software (7.0.1000.8).

    Thanks, Ken

    #2
    I see the problem too,with your sample code. Vista/32 bit/zen fire, 7.0.1000.7


    I ran it on a live Sim101 on current ES 03-12.

    I have 10 days of data loaded on a 1 minute chart, with ES 03-12 daily added to strategy. All those bars show Historical = FALSE.



    Historical = FALSE 0
    CurrentDate=12/19/2011 9:47:36 PM BarsInProgress=0 Historical=False BarTime=12/8/2011 12:24:00 AM
    Historical = FALSE 0
    CurrentDate=12/19/2011 9:47:36 PM BarsInProgress=0 Historical=False BarTime=12/8/2011 12:25:00 AM
    Historical = FALSE 0
    CurrentDate=12/19/2011 9:47:36 PM BarsInProgress=0 Historical=False BarTime=12/8/2011 12:27:00 AM
    Historical = FALSE 0
    .......
    CurrentDate=12/19/2011 9:47:37 PM BarsInProgress=0 Historical=False BarTime=12/19/2011 9:46:00 PM
    Historical = FALSE 0
    CurrentDate=12/19/2011 9:47:37 PM BarsInProgress=0 Historical=False BarTime=12/19/2011 9:47:00 PM
    Historical = FALSE 0
    CurrentDate=12/19/2011 9:47:48 PM BarsInProgress=0 Historical=False BarTime=12/19/2011 9:48:00 PM
    Sending heartbeat...
    Still connected.
    Code:
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
                
                Add("ES 03-12", PeriodType.Day, 1);
                
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                
                if (Historical)
                {
                    Print ( "Historical = TRUE " + BarsInProgress );
                }
                else
                {
                    Print ( "Historical = FALSE " + BarsInProgress );
                }
                    
                    Print(string.Format("CurrentDate={0} BarsInProgress={1} Historical={2} BarTime={3}"
                                        , DateTime.Now.ToString(), BarsInProgress.ToString()
                                        , Historical.ToString(), Time[0].ToString()));
    
            }
    documentation states:

    Definition
    Indicates if the NinjaScript object is running on historical data. With a strategy, when running a backtest, this property will always return true. When running a live strategy, this property will be true until the strategy starts processing real-time data. The property can be of value for many different applications.

    Something is NOT right here!



    Originally posted by hemlock View Post
    I would like to re-raise an old issue (http://www.ninjatrader.com/support/forum/showthread.php?t=34488).

    In summary, in a strategy when a secondary daily series is added to an existing primary series (in this case a 5 minute series) two things occur. First, the historical property always returns false in the OnBarUpdate event, even on the historical bars where the property should be true. Second, the OnBarUpdate event is never fired for the historical bars of the secondary series.

    Please note that when the same code is run within an indicator then everything works as expected (my expectations anyway J). It is only within a strategy that these anomalies exist. Why is the behavior of the software different between an indicator and a strategy?

    I am running a fresh install of the most current version of the software (7.0.1000.8).

    Thanks, Ken

    Comment


      #3
      Interesting, I see the same thing but it only seems to happen with daily bars. I tried a couple other time frames and it worked fine.

      Comment


        #4
        Originally posted by VTtrader View Post
        Interesting, I see the same thing but it only seems to happen with daily bars. I tried a couple other time frames and it worked fine.
        Found this other complaint which *might* be related: (cause undetermined?)




        links to this post which sounds like this issue here:

        Last edited by sledge; 12-19-2011, 10:51 PM.

        Comment


          #5
          Nice work sledge you tracked it down. Not having enough bars seems to have been the issue.

          VT

          Comment


            #6
            Thanks...

            BUT....


            I am Not sure I follow.. I had 10 days of ES data loaded, and the strategy printed a line for every minute from 10 days ago with historical=false. I would expect true until a real time bar was produced...?

            I have recording data on, i don't download if that helps this case.



            Originally posted by VTtrader View Post
            Nice work sledge you tracked it down. Not having enough bars seems to have been the issue.

            VT

            Comment


              #7
              I took the code you pasted above. Used 5min ES chart and added ES daily bars, going back 10 days, and had the same output as you, On one of those links you posted, the NT staff person said to increase the bars loaded to exceed BarsRequired, so I tried 21 days, but that didn't help. Then I tired 50 days (10/30/2011) and the output was correct. As shown by the snippet below.

              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/2/2011 4:00:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/2/2011 4:05:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/2/2011 4:10:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/2/2011 4:15:00 PM
              Historical = TRUE 1
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=1 Historical=True BarTime=12/2/2011 4:15:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/4/2011 6:05:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/4/2011 6:10:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/4/2011 6:15:00 PM
              Historical = TRUE 0
              CurrentDate=12/20/2011 12:30:27 AM BarsInProgress=0 Historical=True BarTime=12/4/2011 6:20:00 PM
              VT

              Comment


                #8
                Would you guys still see the issue if a CurrentBars check for all series is implemented?

                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Sledge, VTtrader and Bertrand - Thanks for your responses.

                  Bertrand,

                  Not exactly sure what you are suggesting but I added CurrentBars[0], CurrentBars{1} and BarsRequired to my print statement and nothing changed. It is interesting though that CurrentBars[1] always has a value of zero. Following is a snippet of my output window and the strategy I am running.

                  BTW, my datafeed is IB....

                  Code:
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 4:50:00 PM BarsSinceSession=198 CurrentBars[0]=1230, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 4:55:00 PM BarsSinceSession=199 CurrentBars[0]=1231, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:00:00 PM BarsSinceSession=200 CurrentBars[0]=1232, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:05:00 PM BarsSinceSession=201 CurrentBars[0]=1233, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:10:00 PM BarsSinceSession=202 CurrentBars[0]=1234, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:15:00 PM BarsSinceSession=203 CurrentBars[0]=1235, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:20:00 PM BarsSinceSession=204 CurrentBars[0]=1236, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:25:00 PM BarsSinceSession=205 CurrentBars[0]=1237, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 5:30:00 PM BarsSinceSession=206 CurrentBars[0]=1238, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 6:05:00 PM BarsSinceSession=207 CurrentBars[0]=1239, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 6:10:00 PM BarsSinceSession=208 CurrentBars[0]=1240, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:16:15 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 6:15:00 PM BarsSinceSession=209 CurrentBars[0]=1241, CurrentBars[1]=0, BarsRequired=20
                  CurrentDate=12/20/2011 6:22:04 PM BarsInProgress=0 Historical=False BarTime=12/20/2011 6:20:00 PM BarsSinceSession=210 CurrentBars[0]=1242, CurrentBars[1]=0, BarsRequired=20
                  Code:
                  [FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{[/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2];[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]Add(PeriodType.Day, [/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]protected [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]override [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2] OnBarUpdate()[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE]
                  [SIZE=2][FONT=Courier New]Print([/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]string[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2].Format([/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000][FONT=Courier New][SIZE=2][COLOR=#800000]"CurrentDate={0} BarsInProgress={1} Historical={2} BarTime={3} BarsSinceSession={4} CurrentBars[0]={5}, CurrentBars[1]={6}, BarsRequired={7}"[/COLOR][/SIZE][/FONT]
                  [/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2], DateTime.Now.ToString(), BarsInProgress.ToString()[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New], Historical.ToString(), Time[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]].ToString(), Bars.BarsSinceSession[/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New], CurrentBars[[/FONT][/SIZE][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], CurrentBars[[/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]], BarsRequired)); [/SIZE][/FONT]
                  [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
                  [/SIZE][/FONT]

                  Comment


                    #10
                    Hemlock,

                    The problem lies in not having enough bars for BarsRequired for all time frames. The check that Bertrand suggests certainly will suppress the output, until there are enough bars for the longer time frame. Another solution is to change the BarsRequired property, as is increasing the number of bars loaded. But as long as BarsRequired is not met on BOTH time frames "Historical" always returns false for both bars series. Why it is different between Indicators and strategies, I don't know.

                    VT
                    Last edited by VTtrader; 12-20-2011, 05:43 PM.

                    Comment


                      #11
                      Just to clarify,

                      OnBarUpdate() is not actually called for the higher time frame, until CurrentBar>BarsRequired, for that time frame. So "Historical" isn't really false, it hasn't even been evaluated for that bars series.

                      For the smaller time frame, OnBarUpdate() is called (since BarsRequired for that time frame is met), but "Historical" will not give a valid result until BOTH bars series have enough bars for BarsRequired.

                      VT

                      Comment


                        #12
                        Thanks VT. I understand your explanation. Is what you say speculation on your part or do you know this to be true? I'm not sure why it needs to be this way seeing that an indicator script does not function the same way. And why would it not have enough bars in the secondary timeframe? I changed my minimum bars required to 5 and it still did not work correctly although I'm not sure why it could not satisfy the default of 20 bars. Do you think this is a bug or is it designed this way? Something is still not making sense to me.

                        Thanks, Ken

                        Comment


                          #13
                          Hemlock,

                          There is some info here... http://www.ninjatrader.com/support/h...b=BarsRequired

                          Also from some of the other threads have discussed it, if you search for BarsRequired. When I tested it, I used a 5min ES chart and added the daily bars and had "10 days" loaded, my output was the same as yours, increasing to even "25 days" wasn't enough (you have to account for weekends/holidays), so then I just added 50 days, and the output was correct. I also tried changing the BarsRequired = 0 (or whatever) and it worked fine. So it works reliably...you just have to change the approach a bit.

                          There was some comment in one of the threads about it being listed as a "code breaking" change for NT7.

                          VT

                          Comment


                            #14
                            Well I found a solution...

                            Setting the BarsRequired for the stategy equal to zero does the trick.

                            Code:
                            [SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff][SIZE=2][FONT=Courier New][COLOR=#0000ff]this[/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][/COLOR][/FONT][/SIZE][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000].BarsRequired = [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000];[/COLOR][/SIZE][/FONT]
                            [/SIZE][/FONT]

                            Thanks all !

                            Comment


                              #15
                              Thanks VT. I guess I just need to be more diligent in reading the docuumentation


                              The fog has lifted.
                              Last edited by hemlock; 12-20-2011, 07:23 PM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by MarianApalaghiei, Today, 10:49 PM
                              3 responses
                              9 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Started by XXtrader, Today, 11:30 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post XXtrader  
                              Started by love2code2trade, Yesterday, 01:45 PM
                              4 responses
                              28 views
                              0 likes
                              Last Post love2code2trade  
                              Started by funk10101, Today, 09:43 PM
                              0 responses
                              9 views
                              0 likes
                              Last Post funk10101  
                              Started by pkefal, 04-11-2024, 07:39 AM
                              11 responses
                              37 views
                              0 likes
                              Last Post jeronymite  
                              Working...
                              X