Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Chris L.NinjaTrader Customer Service

    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 ageeholdings, Today, 07:43 AM
          0 responses
          6 views
          0 likes
          Last Post ageeholdings  
          Started by pibrew, Today, 06:37 AM
          0 responses
          4 views
          0 likes
          Last Post pibrew
          by pibrew
           
          Started by rbeckmann05, Yesterday, 06:48 PM
          1 response
          14 views
          0 likes
          Last Post bltdavid  
          Started by llanqui, Today, 03:53 AM
          0 responses
          6 views
          0 likes
          Last Post llanqui
          by llanqui
           
          Started by burtoninlondon, Today, 12:38 AM
          0 responses
          12 views
          0 likes
          Last Post burtoninlondon  
          Working...
          X