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:	283
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 DJ888, 04-16-2024, 06:09 PM
            6 responses
            18 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by Jon17, Today, 04:33 PM
            0 responses
            1 view
            0 likes
            Last Post Jon17
            by Jon17
             
            Started by Javierw.ok, Today, 04:12 PM
            0 responses
            6 views
            0 likes
            Last Post Javierw.ok  
            Started by timmbbo, Today, 08:59 AM
            2 responses
            10 views
            0 likes
            Last Post bltdavid  
            Started by alifarahani, Today, 09:40 AM
            6 responses
            41 views
            0 likes
            Last Post alifarahani  
            Working...
            X