Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Turning off AutoScale using a custom indicator

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

    Turning off AutoScale using a custom indicator

    My apologies if this has been covered previously, but I couldn't find where it had.

    You can effectively turn off AutoScale in panel 1 by simply drawing a line at the upper and lower limits where you would like to restrict the chart plot movement. This doesn't actually "limit" anything, but, so long as the plot lies between the lines, it does eliminate the jumping around that your chart plot does when scrolling laterally.


    The easiest way to do this is to use the New NinjaScript Indicator Wizard. Name your indicator (say, AutoScaleOff) and be sure to check "Overlay on Price" . Create two double precision input parameters. I call mine "rangeUpper" and "rangeLower". You can set default values, if desired, but you'll be changing these almost every time you start your indicator. Next, create a couple of indicator plots, say, UpperLine and LowerLine. You don't need oscillator lines. Edit the NJ written code for your indicator like I've done below.

    protected override void Initialize()
    {
    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "UpperLine"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "LowerLine"));
    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;
    }

    /// <summary>
    /// Called on each bar update event (incoming tick)
    /// </summary>
    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values. Assign a value to each
    // plot below by replacing 'Close[0]' with your own formula.
    UpperLine.Set(rangeUpper);
    LowerLine.Set(rangeLower);
    }

    Notes:
    Be sure to use double precision input parameters or you'll be restricted to integer range values.
    Don't be tempted to color your limit lines to your background color. It's handy to see them.
    This isn't as useful as it sounds when viewing long periods of data that may have a large range. While the jumping around may be eliminated, much detail will be lost and you'll end up with just a long trace of data that gently slopes up and down.


    You can make your indicator reset to a broader range, should out-of-bounds values come through, by including some simple logic to change "rangeUpper" and "rangeLower" according to current data.

    #2
    Thank you Newton for this guide.
    Josh P.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Jonafare, 12-06-2012, 03:48 PM
    5 responses
    3,986 views
    0 likes
    Last Post rene69851  
    Started by Fitspressorest, Today, 01:38 PM
    0 responses
    2 views
    0 likes
    Last Post Fitspressorest  
    Started by Jonker, Today, 01:19 PM
    0 responses
    2 views
    0 likes
    Last Post Jonker
    by Jonker
     
    Started by futtrader, Today, 01:16 PM
    0 responses
    8 views
    0 likes
    Last Post futtrader  
    Started by Segwin, 05-07-2018, 02:15 PM
    14 responses
    1,792 views
    0 likes
    Last Post aligator  
    Working...
    X