Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

add time period filter to PreviousHLOC indicator

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

    add time period filter to PreviousHLOC indicator

    Is there indicator/script to draw horizontal line on High/Low on previous day's specific time period?

    For example: high/low within 9:30 to 4:00 from previous day, then draw it on today's chart.

    It would look like PreviousHLOC, but with added time restriction. So 2 different PreviousHLOC on chart.

    thanks.

    #2
    MoreYummy, thanks for the post. Please take a look at this sample here - http://www.ninjatrader-support2.com/...ead.php?t=8600

    It should give you a good start toward the direction you need, if this is too much programming, just use a chart with session times set to the ones you need the previous daily high / low for and apply the PriorDayOHLC indicator.

    Comment


      #3
      Hi,

      That one works after a little modifications.

      One thing I dont know how to do is, the default line size is so short, I want to extend it until the end of the day. It already starts at the beginning of the day, just need to extend it till end of day and stop there.

      thanks.

      Comment


        #4
        You would just need to extend the line through your draw object in your code. As a new bar is added you need to redraw the line to include that new bar.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Ok.

          Can you point me to which one is about drawing?

          I cant find one that is related to drawing.

          Could be this?
          Code:
                      // Set the plot values
                      HighestHigh.Set(highestHigh);
                      LowestLow.Set(lowestLow);

          Comment


            #6
            MoreYummy,

            It would be better if you post up your complete script. Thank you.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Here is the script.

              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
              
              // 
              namespace NinjaTrader.Indicator
              {
                  /// <summary>
                  /// 
                  /// </summary>
                  [Description("")]
                  public class SampleGetHighLowByTimeRange : Indicator
                  {
                      #region Variables
                      // Wizard generated variables
                          private int startHour = 9; // Default setting for StartHour
                          private int startMinute = 30; // Default setting for StartMinute
                          private int endHour = 10; // Default setting for EndHour
                          private int endMinute = 15; // Default setting for EndMinute
                      // User defined variables (add any user defined variables below)
                      #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.FromKnownColor(KnownColor.Green), PlotStyle.Line, "HighestHigh"));
                          Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "LowestLow"));
                          CalculateOnBarClose    = true;
                          Overlay                = true;
                          PriceTypeSupported    = false;
                      }
                      
                      private DateTime startDateTime;
                      private DateTime endDateTime;
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          // Check to make sure the end time is not earlier than the start time
                          if (EndHour < StartHour)
                              return;
                         
                          if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))
                              return;
                         
                          if (startDateTime.Date != Time[0].Date)
                          {
                              startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
                              endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);
                          }
                          
                          // Calculate the number of bars ago for the start and end bars of the specified time range
                          int startBarsAgo = GetBar(startDateTime);
                          int endBarsAgo = GetBar(endDateTime);
                          
                          // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range
                          double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];
                          
                          // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
                          double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];
                  
                          // Set the plot values
                          HighestHigh.Set(highestHigh);
                          LowestLow.Set(lowestLow);
                      }
              
                      #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 HighestHigh
                      {
                          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 LowestLow
                      {
                          get { return Values[1]; }
                      }
              
                      [Description("")]
                      [Category("Parameters")]
                      public int StartHour
                      {
                          get { return startHour; }
                          set { startHour = Math.Max(1, value); }
                      }
              
                      [Description("")]
                      [Category("Parameters")]
                      public int StartMinute
                      {
                          get { return startMinute; }
                          set { startMinute = Math.Max(1, value); }
                      }
              
                      [Description("")]
                      [Category("Parameters")]
                      public int EndHour
                      {
                          get { return endHour; }
                          set { endHour = Math.Max(1, value); }
                      }
              
                      [Description("")]
                      [Category("Parameters")]
                      public int EndMinute
                      {
                          get { return endMinute; }
                          set { endMinute = Math.Max(1, value); }
                      }
                      #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 SampleGetHighLowByTimeRange[] cacheSampleGetHighLowByTimeRange = null;
              
                      private static SampleGetHighLowByTimeRange checkSampleGetHighLowByTimeRange = new SampleGetHighLowByTimeRange();
              
                      /// <summary>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      public SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(int endHour, int endMinute, int startHour, int startMinute)
                      {
                          return SampleGetHighLowByTimeRange(Input, endHour, endMinute, startHour, startMinute);
                      }
              
                      /// <summary>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      public SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(Data.IDataSeries input, int endHour, int endMinute, int startHour, int startMinute)
                      {
                          checkSampleGetHighLowByTimeRange.EndHour = endHour;
                          endHour = checkSampleGetHighLowByTimeRange.EndHour;
                          checkSampleGetHighLowByTimeRange.EndMinute = endMinute;
                          endMinute = checkSampleGetHighLowByTimeRange.EndMinute;
                          checkSampleGetHighLowByTimeRange.StartHour = startHour;
                          startHour = checkSampleGetHighLowByTimeRange.StartHour;
                          checkSampleGetHighLowByTimeRange.StartMinute = startMinute;
                          startMinute = checkSampleGetHighLowByTimeRange.StartMinute;
              
                          if (cacheSampleGetHighLowByTimeRange != null)
                              for (int idx = 0; idx < cacheSampleGetHighLowByTimeRange.Length; idx++)
                                  if (cacheSampleGetHighLowByTimeRange[idx].EndHour == endHour && cacheSampleGetHighLowByTimeRange[idx].EndMinute == endMinute && cacheSampleGetHighLowByTimeRange[idx].StartHour == startHour && cacheSampleGetHighLowByTimeRange[idx].StartMinute == startMinute && cacheSampleGetHighLowByTimeRange[idx].EqualsInput(input))
                                      return cacheSampleGetHighLowByTimeRange[idx];
              
                          SampleGetHighLowByTimeRange indicator = new SampleGetHighLowByTimeRange();
                          indicator.BarsRequired = BarsRequired;
                          indicator.CalculateOnBarClose = CalculateOnBarClose;
                          indicator.Input = input;
                          indicator.EndHour = endHour;
                          indicator.EndMinute = endMinute;
                          indicator.StartHour = startHour;
                          indicator.StartMinute = startMinute;
                          indicator.SetUp();
              
                          SampleGetHighLowByTimeRange[] tmp = new SampleGetHighLowByTimeRange[cacheSampleGetHighLowByTimeRange == null ? 1 : cacheSampleGetHighLowByTimeRange.Length + 1];
                          if (cacheSampleGetHighLowByTimeRange != null)
                              cacheSampleGetHighLowByTimeRange.CopyTo(tmp, 0);
                          tmp[tmp.Length - 1] = indicator;
                          cacheSampleGetHighLowByTimeRange = 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>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      [Gui.Design.WizardCondition("Indicator")]
                      public Indicator.SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(int endHour, int endMinute, int startHour, int startMinute)
                      {
                          return _indicator.SampleGetHighLowByTimeRange(Input, endHour, endMinute, startHour, startMinute);
                      }
              
                      /// <summary>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      public Indicator.SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(Data.IDataSeries input, int endHour, int endMinute, int startHour, int startMinute)
                      {
                          return _indicator.SampleGetHighLowByTimeRange(input, endHour, endMinute, startHour, startMinute);
                      }
              
                  }
              }
              
              // This namespace holds all strategies and is required. Do not change it.
              namespace NinjaTrader.Strategy
              {
                  public partial class Strategy : StrategyBase
                  {
                      /// <summary>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      [Gui.Design.WizardCondition("Indicator")]
                      public Indicator.SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(int endHour, int endMinute, int startHour, int startMinute)
                      {
                          return _indicator.SampleGetHighLowByTimeRange(Input, endHour, endMinute, startHour, startMinute);
                      }
              
                      /// <summary>
                      /// 
                      /// </summary>
                      /// <returns></returns>
                      public Indicator.SampleGetHighLowByTimeRange SampleGetHighLowByTimeRange(Data.IDataSeries input, int endHour, int endMinute, int startHour, int startMinute)
                      {
                          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.SampleGetHighLowByTimeRange(input, endHour, endMinute, startHour, startMinute);
                      }
              
                  }
              }
              #endregion
              Thanks.
              Regards.

              Comment


                #8
                MoreYummy, for this it would be best if you changed it to use DrawLine statements with the found HighestHigh / LowestLow values -



                Those could then be extended as needed with each new bar plotted.

                Comment

                Latest Posts

                Collapse

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