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

Unexpected behaviour High[0] Low [0] historic data

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

    Unexpected behaviour High[0] Low [0] historic data

    Hi I have the following lines execute each bar update.

    if (High[0]>htphigh) htphigh = High[0];
    if (Low[0]<htplow) htplow = Low[0];

    Basically I am accumulating the highest high and lowest low for N bars. This works fine for live data coming but for some strange reason htphigh and htplow have the highest and lowest close getting assigned for historic data.

    I figured that it may be OnBarUpdate only being called once a bar on historical data but High [0] should still return the high of the bar should it not? I am tearing my hair out here and hoped that someone could point out where I am beeing stupid!

    The complete snipet just in case--------

    if (CurrentBar != oldbar){ //new bar?
    oldbar = CurrentBar;
    n = n - 1 ; // count it
    if (n == 0) { // reset N period high and low
    n = periods;
    htphigh = Open[0];
    htplow = Open[0];
    }
    }
    if (High[0]>htphigh) htphigh = High[0];
    if (Low[0]<htplow) htplow = Low[0];

    #2
    OK which ever way I cut it High[0] and Low[0] seem to actually return Close[0] on historical data. I guess I must have got hold of the wrong end of the stick somewhere. Any pointers greatfully recieved

    Comment


      #3
      Well the problem seemed to be that I called the plots "High" and "Low". Kind of odd there wasn't a compile time error? Perhaps not the smartest thing to do on my part but I think the compiler should know the difference?

      Comment


        #4
        Not sure I understand. If you call High[0] in the OnBarUpdate() you should get the High price of that current bar.

        If you want the highest high and lowest low you can also try using MAX() and MIN().
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Hi Josh,

          both High[0] and Low[0] appear to actually return Close[0] if you have two plots called High and Low in your code. The compiler gets confused. Now maybe it was foolish to call my plots "High" and "Low" but really the compiler should have given an error. It is easy to demonstrate, simply create a two plot Indicator with the two plots called High and Low. Then OnBarUpdate add:-

          High.Set(High[0]);
          Low.Set(Low[0]);

          What actually plots (for both plots) is the close on historical data. It correctly plots bar high bar low for live data however. Strange .

          Cheers.
          Last edited by NickA; 07-12-2008, 02:46 PM.

          Comment


            #6
            Right. You should never use reserved words unless you are meaning to override them.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Yup absolutely, not sure what I was thinking about. However maybe the compiler should flag it?

              What threw me of course was that it worked on real time data.....weird. Still on the bright side I learnt a bit more about what makes Ninja tick.

              Cheers.

              Comment


                #8
                The compiler is a standard compiler. Those things are generally not flagged. It works because it just assumes you wanted to override it. We will take note of it for you though.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Josh, I am sure there is far more important stuf to deal with. Forgive me if I am flogging a dead horse here. I am still rather curious as to what actually happened. I guess there is a 'standard data series' that is predefined for you? so high[0] is really StandardDataSeries.high[0] or something?

                  How about plots, I guess they are they are actally a special data series too?

                  If these assumptions are correct I am kind of confuse how the property 'High' of one object (StandadardDataSeries) is beeing onfused with the name of another object a plot object caled High?

                  Anyway the main thing is that I managed to fix it but as I say still rather curious. Oh and thanks for your timely reponse too!!

                  Originally posted by Josh View Post
                  The compiler is a standard compiler. Those things are generally not flagged. It works because it just assumes you wanted to override it. We will take note of it for you though.

                  Comment


                    #10
                    Unfortunately I cannot comment on the inner workings. As long as you don't do it you'll stay out of trouble is what i can say. Cheers, have a good remainder of the weekend .
                    Josh P.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DanielTynera, Today, 01:14 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post DanielTynera  
                    Started by yertle, 04-18-2024, 08:38 AM
                    9 responses
                    41 views
                    0 likes
                    Last Post yertle
                    by yertle
                     
                    Started by techgetgame, Yesterday, 11:42 PM
                    0 responses
                    12 views
                    0 likes
                    Last Post techgetgame  
                    Started by sephichapdson, Yesterday, 11:36 PM
                    0 responses
                    2 views
                    0 likes
                    Last Post sephichapdson  
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,615 views
                    0 likes
                    Last Post aligator  
                    Working...
                    X