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

How to Auto Scale Some but Not All Plots in an Indicator

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

    How to Auto Scale Some but Not All Plots in an Indicator

    I'm building an oscillator indicator that has multiple plots.

    How do I program some of the plots to Auto Scale and some not to Auto Scale?

    For example, if an indicator plots three oscillators in one panel of sizes 10, 25, 100 respectively, how do I program the indicator to Auto Scale the two smallest plots and not the largest?

    I want the larger oscillators to 'go off the chart,' while remaining Auto-Scaled on the smaller oscillators on the indicator I'm building.


    Thank you!
    Matthew



    #2
    You can do this by overriding OnCalculateMinMax and only including the plots you are interested in into your calculation of minvalue and maxvalue.
    Bruce DeVault
    QuantKey Trading Vendor Services
    NinjaTrader Ecosystem Vendor - QuantKey

    Comment


      #3
      Thank you, friend!
      I'm digging into it in the Help Guide.

      Comment


        #4
        I'm getting a number of errors centering around issues with OnCalculateMinMax(). Below is the code I'm working with.

        Can anyone help me make this three-oscillator indicator Auto Scale on the two smallest plots and not the largest plot, CMO3, please?


        public class AutoScaleExample : Indicator
        {

        private CMO
        CMO1,
        CMO2,
        CMO3;

        private double smallestPlotValue = double.MaxValue;
        private double largestPlotValue = double.MinValue;

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"AutoScaleExample";
        Name = "AutoScaleExample";
        Calculate = Calculate.OnBarClose;
        IsOverlay = false;

        // Disable auto-scaling for the largest CMO plot
        IsAutoScale = true;
        CMO3.IsAutoScale = false;

        DisplayInDataBox = false;
        DrawOnPricePanel = true;
        DrawHorizontalGridLines = true;
        DrawVerticalGridLines = false;
        PaintPriceMarkers = false;
        ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
        //Disable this property if your indicator requires custom values that cumulate with each new market data event.
        //See Help Guide for additional information.
        IsSuspendedWhileInactive = true;


        AddLine(Brushes.HotPink, 0, "ZeroLine");
        AddPlot(Brushes.Maroon, "Maroon");
        AddPlot(Brushes.Red, "Red");
        AddPlot(Brushes.OrangeRed, "OrangeRed");

        }
        else if (State == State.Configure)
        {

        }
        else if (State == State.DataLoaded)
        {
        CMO1 = CMO(Close, 10); // Maroon
        CMO2 = CMO(Close, 25); // Red
        CMO3 = CMO(Close, 100); // OrangeRed

        }
        }

        protected override void OnBarUpdate()
        {
        MaroonPlot[0] = CMO1[0];
        RedPlot[0] = CMO2[0];
        OrangeRedPlot[0] = CMO3[0];

        }

        public override void OnCalculateMinMax()
        {
        smallestPlotValue = double.MaxValue;
        largestPlotValue = 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 Close[0] is not guaranteed to be in sync

        // Retrieve "Close" value at the current viewable range index
        double plotValue1 = CMO1[index]; double plotValue2 = CMO2[index];

        // Find the two smallest plot values
        smallestPlotValue = Math.Min(smallestPlotValue, Math.Min(plotValue1, plotValue2));
        largestPlotValue = Math.Max(largestPlotValue, Math.Max(plotValue1, plotValue2)); }

        // Finally, set the minimum and maximum Y-Axis values to +/- 50 ticks from the primary close value
        MinValue = smallestPlotValue - 5 * TickSize;
        MaxValue = largestPlotValue + 5 * TickSize;
        }


        region Properties

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> MaroonPlot
        {
        get { return Values[0]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> RedPlot
        {
        get { return Values[1]; }
        }

        [Browsable(false)]
        [XmlIgnore]
        public Series<double> OrangeRedPlot
        {
        get { return Values[2]; }
        }

        #endregion

        }










        Comment


          #5
          Hello Tagliareni,

          Thanks for your notes.

          "I'm getting a number of errors centering around issues with OnCalculateMinMax()."

          What exactly do the error messages state?

          Please send a screenshot of the error messages so we may accurately assist.
          • To send a screenshot with Windows 10 or newer I would recommend using the Windows Snipping Tool.
          • Alternatively to send a screenshot press Alt + PRINT SCREEN to take a screenshot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save it as a jpeg file and send the file as an attachment.
          ​We look forward to assisting further.
          Brandon H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by Shai Samuel, 07-02-2022, 02:46 PM
          4 responses
          98 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Started by DJ888, Yesterday, 10:57 PM
          0 responses
          8 views
          0 likes
          Last Post DJ888
          by DJ888
           
          Started by MacDad, 02-25-2024, 11:48 PM
          7 responses
          160 views
          0 likes
          Last Post loganjarosz123  
          Working...
          X