Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

plot indicator symmetrical vs the horizontal zero line

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

    plot indicator symmetrical vs the horizontal zero line

    Hello,
    is it possible to plot an indicator on the lower panel always symmetrically centered on the horizontal zero line (attached two images of the default NT8 MACD)

    adding instructions similar the following 5 lines

    public override void OnCalculateMinMax()
    {
    MinValue = - math.abs(MIN(macd);MAX(macd));
    MaxValue = + math.abs(MIN(macd);MAX(macd));
    }

    If so, please how could you show how correctly insert these 5 lines?
    Or would you advise to do this in a different way?
    Thank you

    Attached Files
    Last edited by guidoisot; 05-14-2019, 06:59 AM.

    #2
    any help? how to center the scales of the oscillator?

    Click image for larger version

Name:	Centering the zero line of oscillator scales.jpg
Views:	348
Size:	210.3 KB
ID:	1057450

    Comment


      #3
      Hello guidoisot,

      Thank you for your post.

      We have received your note and a NinjaScript Representative will follow up with you on our findings.

      Thanks in advance for your patience.

      Comment


        #4
        Hello guidoisot,

        Thank you for your patience.

        You were on the right track with overriding OnCalculateMinMax. I've attached a sample indicator that applies this to the MACD. You'll notice that I've added a checkbox in the parameters that decides whether it centers on the Zero line or if it uses the normal OnCalculateMinMax.

        Here's how the OnCalculateMinMax() looks:

        Code:
                public override void OnCalculateMinMax()
                {
                    if(IsCenterZero == false)
                    {
                        base.OnCalculateMinMax();
                    }
                    else if (IsCenterZero == true)
                    {
                          // make sure to always start fresh values to calculate new min/max values
                          double tmpMin = double.MaxValue;
                          double tmpMax = double.MinValue;
        
                          // For performance optimization, only loop through what is viewable on the chart
                          for (int index = ChartBars.FromIndex; index <= ChartBars.ToIndex; index++)
                          {
                            // since using Default[0] is not guaranteed to be in sync
                            // retrieve "Default" value at the current viewable range index
                            double plotValueMin = Default.GetValueAt(index);
                            double plotValueMax = Default.GetValueAt(index);
        
                             // figure out which is larger
                            double tmpPlotMax = Math.Max(Math.Abs(plotValueMin), Math.Abs(plotValueMax));
        
                            // return min/max of tmpPlotMax value
                            tmpMin = Math.Min(tmpMin, -tmpPlotMax);
                            tmpMax = Math.Max(tmpMax, tmpPlotMax);
                          }
        
                          // Finally, set the minimum and maximum Y-Axis values to our tmpMin and tmpMax
                          MinValue = tmpMin;
                          MaxValue = tmpMax;
                    }
                }
        You can then take this example and modify it for your own script.

        Here is a link to our help guide on overriding OnCalculateMinMax:


        Please let us know if we may be of further assistance to you.
        Attached Files

        Comment


          #5
          Thank you very much! It does not appear to be a very simple script. I will look at it and try to move the same logic to my indicator. However, if you think it is worth, in the future you may want to add this (pls see image on my post nr.2 above) as a standard feature to the chart properties.
          Thx.
          Last edited by guidoisot; 05-16-2019, 12:45 AM.

          Comment


            #6
            Hello Kate,
            I have been able to modify my script as suggested by your example. The new scaling feature now works fine! Thank you. The only issue, that I have not really understood how and why it happens, is that sometimes the "centered" oscillator goes off scale if the other oscillator on the opposite hand side of the same panel is not centered as well. The solution I have adopted is that of tranforming also this second osclilator in a "centered" one. However, now, with your script modifications, I find a lot easier to read/compare data of oscillators when they are plotted on same panel.
            Best. GT

            Comment

            Latest Posts

            Collapse

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