Announcement

Collapse
No announcement yet.

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.

    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?

        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.

                  Comment

                  Latest Posts

                  Collapse

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