Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is there any existing method that can find

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

    Is there any existing method that can find

    the most recent high and low in terms of wave?

    #2
    atrader, you could take a look at the Swing() indicator for this task -

    Comment


      #3
      Most recent high/low of an indicator?

      Is there a way to compare an indicator (current bar) to the most recent high/low of that indicator no matter how many bars ago the high/low occurred?

      G&M

      Comment


        #4
        gunsnmoney,

        It just means you have to use MAX() and use a period that goes all the way back to the first bar of the chart.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Thanks Josh, but I don't think that will get me what I want. I'm certain that MAX will get me the highest high of my indicator for that chart but what I really want is the most recent high point prior to the current bar.

          I don't know much about drawing horizontal lines but I think it might look like if x(1) > x(o) draw line from x(1) but I don't know how to get the line to stay until it is breached again with a new high.

          G&M

          Comment


            #6
            I have a script that does just that, hang on and I'll get it...

            Comment


              #7
              This script will get your peaks, highest and lowest. When market retraces to within 61.8% of the High or low it will drop it and begin using the current peak for the new High or Low peak. It uses MACD for detecting peaks if you do not have MACDBBLines you can substitute another.

              Code:
              #region Using declarations
              using System;
              using System.ComponentModel;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.Xml.Serialization;
              using NinjaTrader.Cbi;
              using NinjaTrader.Data;
              using NinjaTrader.Gui.Chart;
              #endregion
              
              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
                  /// <summary>
                  /// Enter the description of your new custom indicator here
                  /// </summary>
                  [Description("Enter the description of your new custom indicator here")]
                  public class BegyHunniewellPeaks : Indicator
                  {
                      #region Variables
                      public bool? Indication;
                      private bool[] macdFlag = new bool[2];
                      private bool? PeakSeek;
                      public double CurrentPeakHigh;
                      public double CurrentPeakLow;
                      public int period;
                      public int Fast;
                      public int Slow;
                      public int Smooth;
                      public int numStdDev;
                      #endregion
              
                      /// <summary>
                      /// This method is used to configure the indicator and is called once before any bar data is loaded.
                      /// </summary>
                      protected override void Initialize()
                      {
                          Add(new Plot(Color.Black, PlotStyle.Dot, "PeakHigh"));
                          Add(new Plot(Color.Black, PlotStyle.Dot, "PeakLow"));
                          CalculateOnBarClose    = true;
                          Overlay                = true;
                          PriceTypeSupported    = false;
                          macdFlag[0] = false;
                          macdFlag[1] = false;
                          period = MACDBBLines(12,12,26,9,1).BandPeriod;
                          Fast = MACDBBLines(12,12,26,9,1).Fast;
                          Slow = MACDBBLines(12,12,26,9,1).Slow;
                          Smooth = MACDBBLines(12,12,26,9,1).Smooth;
                          numStdDev = MACDBBLines(12,12,26,9,1).StdDv;
                          CurrentPeakHigh = 0;
                          CurrentPeakLow = 0;
                      }
              
                      // <summary>
                      // Called on each bar update event (incoming tick)
                         // </summary>
                      protected override void OnBarUpdate()
                      {
                          if(Historical)return;
                          if (CurrentPeakHigh < 1 || Input[0] > CurrentPeakHigh)
                          {
                              CurrentPeakHigh = High[1];
                          }
                          if (CurrentPeakLow < 1 || Input[0] < CurrentPeakLow)
                          {
                              CurrentPeakLow = Low[1];
                          }
                          if(CurrentBar < Fast)return;
                          Indication = null;
                          if (macdFlag[0] == false && CrossAbove(MACDBBLines(period,Fast,Slow,Smooth,numStdDev).dotSeries, MACDBBLines(period,Fast,Slow,Smooth,numStdDev).BB_LowerBand,8))
                          {    
                              macdFlag[0] = true;
                          }
                          
                          if (macdFlag[0] == true && CrossAbove(MACDBBLines(period,Fast,Slow,Smooth,numStdDev).dotSeries, MACDBBLines(period,Fast,Slow,Smooth,numStdDev).BB_UpperBand,8))
                          {
                              if (Low[LowestBar(Low,16)] <= ((CurrentPeakHigh - CurrentPeakLow) * .382) + CurrentPeakLow)
                              {
                                  [COLOR=Red]CurrentPeakLow = Low[LowestBar(Low,16)];[/COLOR]
                              }
                              macdFlag[0] = false;
                              Indication = true;
                          }
              
                          if (macdFlag[1] == false && CrossBelow(MACDBBLines(period,Fast,Slow,Smooth,numStdDev).dotSeries, MACDBBLines(period,Fast,Slow,Smooth,numStdDev).BB_UpperBand,1))
                          {
                              macdFlag[1] = true;
                          }
                          
                              
                          if (macdFlag[1] == true && CrossBelow(MACDBBLines(period,Fast,Slow,Smooth,numStdDev).dotSeries, MACDBBLines(period,Fast,Slow,Smooth,numStdDev).BB_LowerBand,1))
                          {
                              if (High[HighestBar(High,16)]  >= ((CurrentPeakHigh - CurrentPeakLow) * .618) + CurrentPeakLow)
                              {[COLOR=Red]
                                  CurrentPeakHigh = High[HighestBar(High,16)];[/COLOR]
                              }
                              macdFlag[1] = false;
                              Indication = false;
                          }
                          PeakHigh.Set(CurrentPeakHigh);
                          PeakLow.Set(CurrentPeakLow);
                      }
              
                      #region Properties
                      [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                      [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                      public DataSeries PeakHigh
                      {
                          get { return Values[0]; }
                      }
              
                      [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
                      [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
                      public DataSeries PeakLow
                      {
                          get { return Values[1]; }
                      }
               
                     #endregion
                  }
              }
              
              #region NinjaScript generated code. Neither change nor remove.
              // This namespace holds all indicators and is required. Do not change it.
              namespace NinjaTrader.Indicator
              {
                  public partial class Indicator : IndicatorBase
                  {
                      private BegyHunniewellPeaks[] cacheBegyHunniewellPeaks = null;
              
                      private static BegyHunniewellPeaks checkBegyHunniewellPeaks = new BegyHunniewellPeaks();
              
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      public BegyHunniewellPeaks BegyHunniewellPeaks()
                      {
                          return BegyHunniewellPeaks(Input);
                      }
              
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      public BegyHunniewellPeaks BegyHunniewellPeaks(Data.IDataSeries input)
                      {
              
                          if (cacheBegyHunniewellPeaks != null)
                              for (int idx = 0; idx < cacheBegyHunniewellPeaks.Length; idx++)
                                  if (cacheBegyHunniewellPeaks[idx].EqualsInput(input))
                                      return cacheBegyHunniewellPeaks[idx];
              
                          BegyHunniewellPeaks indicator = new BegyHunniewellPeaks();
                          indicator.BarsRequired = BarsRequired;
                          indicator.CalculateOnBarClose = CalculateOnBarClose;
                          indicator.Input = input;
                          indicator.SetUp();
              
                          BegyHunniewellPeaks[] tmp = new BegyHunniewellPeaks[cacheBegyHunniewellPeaks == null ? 1 : cacheBegyHunniewellPeaks.Length + 1];
                          if (cacheBegyHunniewellPeaks != null)
                              cacheBegyHunniewellPeaks.CopyTo(tmp, 0);
                          tmp[tmp.Length - 1] = indicator;
                          cacheBegyHunniewellPeaks = tmp;
                          Indicators.Add(indicator);
              
                          return indicator;
                      }
              
                  }
              }
              
              // This namespace holds all market analyzer column definitions and is required. Do not change it.
              namespace NinjaTrader.MarketAnalyzer
              {
                  public partial class Column : ColumnBase
                  {
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      [Gui.Design.WizardCondition("Indicator")]
                      public Indicator.BegyHunniewellPeaks BegyHunniewellPeaks()
                      {
                          return _indicator.BegyHunniewellPeaks(Input);
                      }
              
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      public Indicator.BegyHunniewellPeaks BegyHunniewellPeaks(Data.IDataSeries input)
                      {
                          return _indicator.BegyHunniewellPeaks(input);
                      }
              
                  }
              }
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  public partial class Strategy : StrategyBase
                  {
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      [Gui.Design.WizardCondition("Indicator")]
                      public Indicator.BegyHunniewellPeaks BegyHunniewellPeaks()
                      {
                          return _indicator.BegyHunniewellPeaks(Input);
                      }
              
                      /// <summary>
                      /// Enter the description of your new custom indicator here
                      /// </summary>
                      /// <returns></returns>
                      public Indicator.BegyHunniewellPeaks BegyHunniewellPeaks(Data.IDataSeries input)
                      {
                          if (InInitialize && input == null)
                              throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
              
                          return _indicator.BegyHunniewellPeaks(input);
                      }
              
                  }
              }
              #endregion
              this is the script in full just cut and paste what you need to your script.

              Note the area in red, this goes back once the MACD detects a peak and finds the absolute peak.
              Last edited by Sleeping Troll; 04-07-2010, 11:03 PM.

              Comment


                #8
                ST, thanks for the script. I'm sure my solution is in there somewhere but I'm not a programmer so I'm having rubble figuring out what to do.

                It may have been easier if you had zipped it as an NT indicator and posted (or is it posted somewhere?). Then I could see how it works and maybe just applied it to the indicator I'm using within the strategy.

                G&M

                Comment


                  #9
                  If you are knew at this, by the time you get what you need from this script you will have learned a great deal, Enjoy! Feel free to PM with Q's
                  Last edited by Sleeping Troll; 04-09-2010, 09:13 PM.

                  Comment

                  Latest Posts

                  Collapse

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