Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to retrieve current values for several indicators on a chart

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

    How to retrieve current values for several indicators on a chart

    Hello,
    I'm trying to develop a script that will inspect the current values of several indicators plotted on a chart so that I can determine if they are converging or diverging.
    Based on an example using ChartControl, I'm using the following code to print details of the indicators:

    Code:
    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    // Instantiate a ChartObjectCollection to hold chartControl.Indicators
    ChartObjectCollection<NinjaTrader.Gui.NinjaScript. IndicatorRenderBase> indicatorCollection = chartControl.Indicators;
    
    // Print the Calculate setting for any configured indicators not using Calculate.OnBarClose
    foreach (NinjaTrader.Gui.NinjaScript.IndicatorRenderBase indicator in indicatorCollection)
    {
    if(indicator.Calculate != Calculate.OnBarClose)
    Print(String.Format("{0} is using Calculate.{1}", indicator.Name, indicator.Calculate.ToString()));
    if(indicator.Name != "IndiValue")
    Print(String.Format("{0} current value is {1}", indicator.Name, indicator.GetValueAt(CurrentBar).ToString()));
    }
    }
    However, the indicator.GetValueAt attribute in the last line always returns the current value of the main chart instrument, not that of the indicator.
    Is it possible to retrieve each of the current indicator values?

    #2
    Hello Scotty33,

    Thanks for your post.

    indicator.GetValueAt(CurrentBar) would get the bar value on the chart.

    You could consider trying indicator.Values[0].GetValueAt(CurrentBar) to get the indicator value on the chart.

    This is noted on the GetValueAt() help guide page linked below.

    GetValueAt(): https://ninjatrader.com/support/help...getvalueat.htm
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thanks Brandon. That worked.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      599 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      345 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X