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

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:	285
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:


        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 kempotrader, Today, 08:56 AM
            0 responses
            7 views
            0 likes
            Last Post kempotrader  
            Started by kempotrader, Today, 08:54 AM
            0 responses
            4 views
            0 likes
            Last Post kempotrader  
            Started by mmenigma, Today, 08:54 AM
            0 responses
            2 views
            0 likes
            Last Post mmenigma  
            Started by halgo_boulder, Today, 08:44 AM
            0 responses
            1 view
            0 likes
            Last Post halgo_boulder  
            Started by drewski1980, Today, 08:24 AM
            0 responses
            4 views
            0 likes
            Last Post drewski1980  
            Working...
            X