Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting junk values from Highs[1][x] and Lows[1][x]

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

    Getting junk values from Highs[1][x] and Lows[1][x]

    In Initialise()

    CalculateOnBarClose = false;
    Add(PeriodType.Minute,15);

    Calling below code on OnStartUp()
    Code:
    private void PrintOHLCvaluesfortimebars(int fromxbars,int to_ybars)
    {
    			var instance = new GetBuySellPrint();
    			
    			double open = 0; 
    			double high =0;
    			double low= 0;
    			double close =0;
    			double prevbarhigh =Highs[1][fromxbars];
    			double prevbarlow =Lows[1][fromxbars];		
    			
    			for(int x=fromxbars;x<to_ybars;x++)
    			{				
    				high = Highs[1][x];
    				low = Lows[1][x];
    				Print("Some high="+ Highs[0][x]);
    				Print("Some low ="+ Lows[0][x]);
    				if(Math.Round(high,2)>=Math.Round(prevbarhigh,2))
    				{
    					prevbarhigh = high;
    				}
    				if(Math.Round(low,2)<=Math.Round(prevbarlow,2))
    				{
    					prevbarlow = low;
    				}
    				
    			}
    }
    This is the output i am getting from using Highs and Lows
    Some high=103.34
    Some low =103.31
    Some high=103.34
    Some low =103.27
    Some high=103.4
    Some low =103.29
    Some high=103.43
    Some low =103.39
    barstillpitopen = -1
    barstillglobexopen = 4

    Which should have been in fact in the range 104.15 to 104.23 .
    Why am i getting junk values.?
    Please help.

    I wanted historical highs and lows of 15 min bars from some x time to y time.

    #2
    nemesis45, why would you run this from OnStartUp()? That's just a one time event called before any OnBarUpdate().

    Comment


      #3
      Because i only need to run this code once.
      Eg. Get highs and lows for the time period since my code has started to a fixed period in history eg. 1:00 pm IST globex session begin or 6:30 pm IST, us pit open begin etc.

      So i only need to run this once.
      but why is it returning junk values.

      Since it's already been initialised in Initialise()?

      Comment


        #4
        I would not make any sense to run the code in this place. This is called before any OnBarUpdate(), so before any bars processing would be done (i.e. before CurrentBar zero is started).

        Comment


          #5
          oh ok , got it.

          hmm, but the problem is that if i put this in OnBarUpdate() , itll add an extra if statement before each bar is processed.

          On a side note. If CalculateOnBarClose is set to false, the OnBarUpdate() gets called for each incoming tick is what is written in your help guide.

          that would be for a BarsIndex of 0 right?
          If i add another series via.

          Add(PeriodType.Minute,15);
          Itll have an index of 1 and then OnBarUpdate() also gets called additional every 15 mins?
          and i can access it through if (BarsInProgress == 1) in the OnBarUpdate()? will work?

          I did not want to use OnBarUpdate() so far in my program, instead using the timer.
          I dont want it to be called every tick, will increase processing overhead.
          Is there any way to change it to being called every 15 mins and stop it being called on every tick.
          OnMarketUpdate() gets called irrespective whether CalculateOnBarClose is set to true or false?

          Also can i make another script run from my ninjascript?
          Also no way to get open, high, low close values ?
          if i put this in OnBarUpdate(), it would get called on every bar update, but i only need to do it once.
          Last edited by nemesis45; 04-21-2014, 03:38 AM.

          Comment


            #6
            Correct, CalculateOnBarClose is applicable to all bar indices in OnBarUpdate(), OnMarketData is not build on bars events, but solely Level 1 data events.

            OnBarUpdate() is processed for all bar events and your BarsInProgress would be the filter, which ones you want your code to 'listen' to.

            For a one time thing, perhaps just capture what you need in OnBarUpdate() once first realtime bar is seen?



            That way you don't have any historical processing and could process one time via a bool flag.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              Correct, CalculateOnBarClose is applicable to all bar indices in OnBarUpdate(), OnMarketData is not build on bars events, but solely Level 1 data events.

              OnBarUpdate() is processed for all bar events and your BarsInProgress would be the filter, which ones you want your code to 'listen' to.

              For a one time thing, perhaps just capture what you need in OnBarUpdate() once first realtime bar is seen?



              That way you don't have any historical processing and could process one time via a bool flag.
              So OnMarketData() doesnt care if calculateonbarclsoe is set to false or not?
              That can work i guess.

              if calculateonbarclose is applicabple for all OnBarUpdate events doesnt OnBarUpdate become redundant if calculateonbarclose is set to false? since it keeps getting called for each incoming tick and i want it to be called only every 15 mins? (i will set calculateonbarclose to true if OnMarketData() is independent of it, so just asking for my knowledge)

              Certainly i can use a bool flag, but then i'd have to check for the flag on every OnBarUpdate(), in that case i wouldnt want it to get called for each incoming tick. so just need clarification there.
              would following code work

              CalculateONBarClose =false;

              Add(PeriodType.Minute.15);

              OnBarUpdate()
              {
              if(BarsInProgress = 1)
              {
              // Do something every 15 mins
              }
              }

              or will it do something on every tick?

              Comment


                #8
                Correct, OnMarketData() is not tied to any bars update or CalculateOnBarClose setting.

                This would still do something every tick then, you could limit via calling in FirstTickOfBar context

                Comment


                  #9
                  Thanks, guess ill just set CalculateOnBarClose to true

                  Comment


                    #10
                    Just one last thing please.
                    Suppose i set
                    CalculateOnBarClose = true;

                    Add(PeriodType.Minute,15)

                    OnBarUpdate()
                    {
                    // do something
                    }

                    Lets say the current time is 6:20.

                    What exactly happens among
                    a) OnBarUpdate() first gets called at 6:20 , and subsequently gets called at 6:35 , then 6:50 so on.
                    b)OnBarUpdate() first gets called at 6:30, then gets called at 6:45, 7:00 and so on, synced with my computer's lock.

                    Comment


                      #11
                      Hello nemesis45,

                      Thank you for your response.

                      The bars of 15 minute will be called on the 15 minute close with CalculateOnBarClose = true, and this close is based on when the session open is. So if the session open is on :00, : 15, :30, or :45, then the close will be on the 15 minute mark. But if the session open was in fact 6:20 then the next close would be 6:35. So the answer is base don the session open time.

                      Comment


                        #12
                        How is session open defined?
                        is it the same as open outcry? or can i manually define session on ninja?

                        Comment


                          #13
                          Hello nemesis45,

                          Thank you for your response.

                          This is defined by a Session Template in NinjaTrader. These are applied in the Data Series menu of the Chart or on the Strategies tab through the Strategy menu.

                          You can view these Session Templates by going to Tools > Session Manager. Each instrument has a Session Template assigned to it for the option <Use Instrument Settings> in the Data Series menu. You can view which Session Template the instrument is assigned to by going to Tools > Instrument Manager > search for the instrument > select the instrument from the search results > Edit > Session Template.

                          For information on Session Templates and the Session Manager please visit the following link: http://www.ninjatrader.com/support/h...on_manager.htm

                          Please let me know if I may be of further assistance.

                          Comment


                            #14
                            Originally posted by NinjaTrader_PatrickH View Post
                            Hello nemesis45,

                            Thank you for your response.

                            This is defined by a Session Template in NinjaTrader. These are applied in the Data Series menu of the Chart or on the Strategies tab through the Strategy menu.

                            You can view these Session Templates by going to Tools > Session Manager. Each instrument has a Session Template assigned to it for the option <Use Instrument Settings> in the Data Series menu. You can view which Session Template the instrument is assigned to by going to Tools > Instrument Manager > search for the instrument > select the instrument from the search results > Edit > Session Template.

                            For information on Session Templates and the Session Manager please visit the following link: http://www.ninjatrader.com/support/h...on_manager.htm

                            Please let me know if I may be of further assistance.
                            Thanks a lot.I take it i cant create and apply templates inside of the code?

                            Comment


                              #15
                              Hello nemesis45,

                              Unfortunately, this is not possible. The Session Template must be applied via the Data Series menu and options. The Session Template selected will be applied to all instruments and time frames in the code.

                              Comment

                              Latest Posts

                              Collapse

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