Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Indicator High Low Values

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

    Getting Indicator High Low Values

    Hello,

    I'm having an issue with an indicator that I'm working on that uses HMA(30). My goal is to get the High, Low, Open, Close of HMA for the working bar. How can I get the Max High and Min Low for HMA(30)[0] while it calculates on each tick or on price change?

    Here is my code so far:
    Code:
    protected override void OnStateChange()
    
    if (State == State.SetDefaults)
    Calculate = Calculate.OnEachTick
    
    AddPlot(new Stroke(Brushes.Lime, 1), PlotStyle.Square, "HMAHigh");
    AddPlot(new Stroke(Brushes.Red, 1), PlotStyle.Square, "HMALow");
    AddPlot(new Stroke(Brushes.DodgerBlue, 1), PlotStyle.Square, "HMAOpen");
    AddPlot(new Stroke(Brushes.Goldenrod, 1), PlotStyle.Square, "HMAClose");
    
    protected override void OnBarUpdate()
    
    if (BarsInProgress != 0)
    return; 
    
    if (CurrentBars[0] < 33)
    return;
    
    Print(">>>Price Change<<<");    
    
    HMAOpen[0] = Math.Round(HMA(30)[1],2);
    HMAClose[0] = Math.Round(HMA(30)[0],2);
    HMAHigh[0] = Math.Round(Math.Max(HMAOpen[0],HMAClose[0]),2);
    HMALow[0] = Math.Round(Math.Min(HMAOpen[0],HMAClose[0]),2);
    
    Print("HMAHigh = "+HMAHigh[0]);
    Print("HMALow = "+HMALow[0]);
    Print("HMAOpen = "+HMAOpen[0]);
    Print("HMAClose = "+HMAClose[0]);
    Here is my Output: (NQ 06-19)
    Code:
    >>>Price Change<<<
    HMAHigh = 7621.47
    HMALow = 7621.07
    HMAOpen = 7621.47
    HMAClose = 7621.07
    The issue is that the HMAHigh is always equal to HMAOpen and HMALow is always equal to HMAClose.
    How can I get accurate HMAHigh and HMALow values?

    #2
    Hello KINGKODA,

    Thanks for your post.

    You could use the bool Bars.ISFirstTickOfBar as the starting point to populate the HMAOpen as well as to save the same value into two local variables to hold the tempLow and tempHigh.
    After the first tick of the bar, on each price change or each tick of bar, you would compare the current value of the HMA(30) and if higher than the tempMax you write the new value to tempMax and update your HMAHigh[0] plot, same with the tempLow when the current HMA(30) is less than the tempLow. HMAClose[0] will always be the current HMA(30) value.
    Reference: https://ninjatrader.com/support/help...ttickofbar.htm

    I've not run across what you are trying to do before and I am wondering if you are really wanting instead to use 4 HMAs that are based on the price types of Open, High, Low and Close. This would be coded as:
    HMAopen[0] = HMA(Open, 30)[0]; // uses the open price series
    HMAClose[0] = HMA(30)[0]; // Close is always the default when expressed like this.
    HMAHigh[0] = HMA(High, 30)[0]; // uses the high price series
    HMALow[0] = HMA(Low, 30)[0]; // uses the low price series

    Reference: https://ninjatrader.com/support/help...riceseries.htm

    Comment


      #3
      Hey Paul,

      Thanks for your response. I am not interested in getting the HMA of price types{Open, High, Low, Close}. What I am interested in is the reverse, getting the Open, High, Low, Close of the HMA indicator.

      I implemented your advice using tempMax / tempMin and I got very close to my goal but every time I refresh the chart, HMAHigh and HMALow disappear.

      This is my updated code:
      Code:
      if (IsFirstTickOfBar)
                  {
                      HMAOpen[0] = HMA(7)[1];
                      tempMax = 0;
                      tempMin = 1000000000;
                  }
      
                  HMAClose[0] = HMA(7)[0];
      
                  if (Math.Round(Math.Max(HMAOpen[0],HMAClose[0]),2)>tempMax)
                  {
                      HMAHigh[0] = Math.Round(Math.Max(HMAOpen[0],HMAClose[0]),2);
                      tempMax = Math.Round(Math.Max(HMAOpen[0],HMAClose[0]),2);
                  }
      
                  if (Math.Round(Math.Min(HMAOpen[0],HMAClose[0]),2)<tempMin)
                  {
                      HMALow[0] = Math.Round(Math.Min(HMAOpen[0],HMAClose[0]),2);
                      tempMin = Math.Round(Math.Min(HMAOpen[0],HMAClose[0]),2);
                  }
      Once I refresh the chart, HMAHigh and HMALow disappear. How can I get the values historically? I've attached pictures before and after chart refresh.

      Before Refresh we can see the HMALow(red) HMAHigh(lime) HMAOpen(blue) HMAClose(orange)
      Click image for larger version

Name:	Before Refresh.JPG
Views:	1110
Size:	40.8 KB
ID:	1054238

      After Refresh HMAHigh and HMALow disappear. How can I fix this?Click image for larger version

Name:	After Refresh.JPG
Views:	967
Size:	48.8 KB
ID:	1054239

      Comment


        #4
        Hello KINGKODA,

        Thanks for your post.

        The issue is that those values come from tick data. When you refresh your chart, the indicator recalculates based on the historical data which only provides the OHLC of the bar and not of the ticks that make up the bar. Historically the data is calculated the same as if Calculate.OnBarClose.

        To accomplish your goal you would need to enable Tick Replay on the data series.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        600 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        347 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
        558 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        558 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X