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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      80 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X