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

Dynamic Auto Scaling

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

    Dynamic Auto Scaling

    I've created an indicator which plots the 52 week high/low as well as some other plots. There are times when the 52 high/low are far beyond the range of the current price resulting in a unreadable set of candlesticks. I want my other plots to auto scale but not the 52 week high/low if they're not near the current price range being displayed. Is there a way to achieve this using Ninjascript? Do I need to hide the plots programatically using my own criteria? Is it even possible to dynamically hide a single indicator plot using NS?

    Thanks.

    #2
    Hello stoner,

    Thanks for your question.

    By default, the script's Auto Scale behavior will adjust scaling to include objects and plots. You can override the auto scale behavior using OnCalculateMinMax. Please see documentation below for more details.

    OnCalculateMinMax - https://ninjatrader.com/support/help...lateminmax.htm

    I look forward to being of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      The sample code in that link was helpful. But I had to modify it a bit and this might help other people. My Indicator has two data series that use the same primary instrument with 2 separate time frames. The main time frame (BarsArray[0]) is driven by the NT charting UI. The second time frame (BarysArray[1]) is uses a hard coded Daily time frame.

      The issue was the sample code below assumes that the Close's underlying array is the BarsArray[0] structure but it wasn't in my case and I was getting an index related exception...

      Code:
      double plotValue = Close.GetValueAt(index);
      So I updated the code to make sure the ChartBars and BarsArray[0] are the same size and then I'm getting the Close from BarsArray[0].GetClose()...

      Code:
      public override void OnCalculateMinMax()
      {
      [B]if (ChartBars.Count == BarsArray[0].Count) {[/B]
            // 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 Close[0] is not guaranteed to be in sync
               // retrieve "Close" value at the current viewable range index
               double plotValue = [B]BarsArray[0].GetClose[/B](index);
      
               // return min/max of close value
               tmpMin = Math.Min(tmpMin, plotValue);
               tmpMax = Math.Max(tmpMax, plotValue);
            }
      
            // Finally, set the minimum and maximum Y-Axis values to +/- 50 ticks from the primary close value
            MinValue = tmpMin - 10 * TickSize;
            MaxValue = tmpMax + 10 * TickSize;
      [B]   }
         else
         {
            base.OnCalculateMinMax();
         }[/B]
      }
      Not sure why the ChartBars has the correct FromIndex/ToIndex and the wrong underlying BarsArray but it does in my case.

      Hope this helps.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      3 views
      0 likes
      Last Post jaybedreamin  
      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  
      Working...
      X