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

High and Low of custom indicator

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

    High and Low of custom indicator

    Hi,

    I have a custom indicator and I would like to know how can I programmatically return the high and low of the indicator for the current session.

    I am calculating the spread between two instruments as follows which works great;

    Code:
     
    protected override void OnBarUpdate()
            {
                // Calculate the spread between instruments
                myDataSeries.Set(Closes[1][0] - Closes[2][0]);
            }
    I have tried using LowestBar but that returns every bar...do I need to do something using IDataSeries instead? I'm not sure so I would appreciate some help.

    Regards,
    suprsnipes
    Last edited by suprsnipes; 10-10-2012, 09:33 PM. Reason: Add some further information

    #2
    suprsnipes, you can look into the MAX / MIN methods over a lookback of BarsSinceSession.






    More efficient would be then custom tracking the highest / lowest value seen with your own variable.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      Thanks for your response. I have used the following line of code and whilst it works for part of the session I'm getting 0 values for the last couple of hours. The session I am using is US Equities RTH and the value's seem to 0 out for the last couple hours why would this occur?

      Code:
      double max = MAX(myDataSeries, Bars.BarsSinceSession)[0];
      Bascially I just want to return in this case the maximum value of myDataSeries as the day progresses...am I doing this incorrectly?

      Regards,
      suprsnipes

      Comment


        #4
        What data series are you feeding into it? Would the changing to 0 occur after the session's been reset to start fresh?
        BertrandNinjaTrader Customer Service

        Comment


          #5
          Hi,

          The changing to 0 occurs at exactly the same time daily...4:47am. The session template is from 1230am to 7am (local AEST set to 830am - 3pm Chicago Time). Please see the output.txt file attached.

          The data series is the spread between the ES 12-12 and YM 12-12.

          The code is basic and looks like this.

          Code:
          protected override void OnBarUpdate()
                  {
                      if (CurrentBars[0] < 5) 
                      return;
                      
                      // Calculate the spread between instruments
                      myDataSeries.Set(Math.Round((Closes[1][0] - Closes[2][0]), 2));
                      
                      Plot0.Set(myDataSeries[0]);
                      
                      double max = MAX(myDataSeries, Bars.BarsSinceSession)[0];
                      double min = MIN(myDataSeries, Bars.BarsSinceSession)[0];
                      
                      // Print the current, minimum and maximum values
                      Print("Current Value is " + myDataSeries + " Maximum Value is " + max + " | Minimum Value is " + min + " T " + Time[0]);
                  }
          Attached Files
          Last edited by suprsnipes; 10-11-2012, 04:44 PM.

          Comment


            #6
            Just solved this problem, I added in the initialize section the following piece of code to increase the number of bars for the look back period from 256 to infinite. It's working as expected now.

            Code:
            protected override void Initialize()
            {
            // Store all series values instead of only the last 256 values
                        MaximumBarsLookBack = MaximumBarsLookBack.Infinite;
            }
            Hopefully if another member has the same issue this will help them to rectify it.
            suprsnipes

            Comment


              #7
              Ok, now that I have the minimum and maximum values of my custom data series what method can I use to be able to identify which bar that new max and or new min has been established? I want to be able to use that bar...

              I have tried the following but it doesn't work?? What am I doing wrong?

              Code:
              Print(HighestBar(myDataSeries, Bars.BarsSinceSession - 1).ToString());
              Regards,
              suprsnipes
              Last edited by suprsnipes; 10-11-2012, 07:34 PM.

              Comment


                #8
                Ok, it does work. Obviously I can't read...and enjoy talking to myself

                Definition
                Returns the number of bars ago the highest price value occurred for the lookback period.

                Silly.

                Comment


                  #9
                  Glad you were able to get things worked out. If you need anything else please let us know.
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by adeelshahzad, Today, 03:54 AM
                  4 responses
                  24 views
                  0 likes
                  Last Post adeelshahzad  
                  Started by merzo, 06-25-2023, 02:19 AM
                  10 responses
                  823 views
                  1 like
                  Last Post NinjaTrader_ChristopherJ  
                  Started by frankthearm, Today, 09:08 AM
                  5 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Started by jeronymite, 04-12-2024, 04:26 PM
                  3 responses
                  43 views
                  0 likes
                  Last Post jeronymite  
                  Started by yertle, Today, 08:38 AM
                  5 responses
                  16 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Working...
                  X