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 Mindset, 04-21-2026, 06:46 AM
      0 responses
      65 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      94 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      52 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by cmoran13, 04-16-2026, 01:02 PM
      0 responses
      108 views
      0 likes
      Last Post cmoran13  
      Started by PaulMohn, 04-10-2026, 11:11 AM
      0 responses
      63 views
      0 likes
      Last Post PaulMohn  
      Working...
      X