• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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:	1
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.
      Kate W.NinjaTrader Customer Service

      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:
        https://ninjatrader.com/support/help...lateminmax.htm

        Please let us know if we may be of further assistance to you.
        Attached Files
        Kate W.NinjaTrader Customer Service

        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 nepenthean, Today, 08:01 AM
            0 responses
            3 views
            0 likes
            Last Post nepenthean  
            Started by bxl2019, Today, 07:59 AM
            0 responses
            2 views
            0 likes
            Last Post bxl2019
            by bxl2019
             
            Started by tcfcigvo, Yesterday, 11:39 PM
            0 responses
            7 views
            0 likes
            Last Post tcfcigvo  
            Started by BobbyWan, Yesterday, 09:15 PM
            0 responses
            11 views
            0 likes
            Last Post BobbyWan  
            Started by trader14, Yesterday, 08:23 PM
            0 responses
            6 views
            0 likes
            Last Post trader14  
            Working...
            X