Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnCalculateMinMax() Override Not Updating Upon Chart Zoom

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

    OnCalculateMinMax() Override Not Updating Upon Chart Zoom

    Hi all,

    I have developed an indicator which overrides OnCalculateMinMax() and it appears to be working correctly when it's first loaded, however if I zoom out and then zoom back in the indicator will still use the scale from a point of zoom where the min/max range was at its greatest.

    Is there code that I can add that can force the update? not sure why it wouldn't already be doing this I thought OnCalculateMinMax() was supposed to be called when user drags, scrolls, etc...

    below is the code from my override:
    Code:
    public override void OnCalculateMinMax()
    {
    // base.OnCalculateMinMax();
    
    if (Bars == null || ChartControl == null)
    return;
    
    for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
    {
    double tmpHigh = iHigh.GetValueAt(idx);
    double tmpLow = iLow.GetValueAt(idx);
    
    if (tmpHigh != 0 && tmpHigh > MaxValue)
    MaxValue = tmpHigh;
    if (tmpLow != 0 && tmpLow < MinValue)
    MinValue = tmpLow;
    }
    }
    Thanks in advance!​

    #2
    Hello, thanks for writing in. Your implementation is not quite the same as the example in the help guide. We are setting a min and max value for the chart at the beginning of this method, so your code may not be reaching the for loop at times, resulting in the behavior you are seeing.

    Comment


      #3
      Hi Chris,

      Thanks for the response, I have altered the code to be as close to the reference code as possible (I am calculating min/max for rendered candlesticks not 'plotValue' so it can't be exactly the same.

      Looks like:
      Code:
      public override void OnCalculateMinMax()
      {
      // base.OnCalculateMinMax();
      
      // if (Bars == null || ChartControl == null)
      // return;
      
      for (int idx = ChartBars.FromIndex; idx <= ChartBars.ToIndex; idx++)
      {
      double tmpHigh = iHigh.GetValueAt(idx);
      double tmpLow = iLow.GetValueAt(idx);
      
      MaxValue = Math.Max(tmpHigh, MaxValue);
      MinValue = Math.Min(tmpLow, MinValue);
      }
      }
      I am seeing the same issue where the scale doesn't reset once I zoom back in. Do you know how I could modify this code to update the values?​

      Comment


        #4
        That's because you're not setting MinValue and MaxValue at the top of the method so they're only ever zooming in. You need to make it back like the example - you have moved the definitions of tmpHigh and tmpLow into the loop, and that is wrong. They need to be defined outside the loop so they start off not zoomed, and there's no need to set MinValue and MaxValue inside the loop - set them at the end. By setting them each bar, what you're doing is only ever zooming tighter and tigher. It is the changes you have made that have broken the example in this way.
        Bruce DeVault
        QuantKey Trading Vendor Services
        NinjaTrader Ecosystem Vendor - QuantKey

        Comment


          #5
          Seems you are right. It was working before with my code under different conditions, not sure why. Thanks.

          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
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          573 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          575 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X