Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

retrieve the value of an indicator

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

    retrieve the value of an indicator

    Hello
    I'm using the function below to retrieve the value of an indicator displayed on the chart.
    If this code is in OnBarUpdate(), it works perfectly.
    If it's outside, it only works partially.
    Indeed, indicator.Name is displayed perfectly (I'm displaying the name of the indicator) whereas instead of having plot (the name of the output as displayed in the databox), I have NinjaTrader.Gui.Plot.
    Also val is always 0!
    Is what I'm looking for possible outside OnBarUpdate()?
    If so, what's wrong with my code?
    Thank you in advance for your help.

    Code:
    private double GetIndic (string Name,string MyPlot, int index)
            {
                double retour = -1;
                foreach (IndicatorBase indicator in ChartControl.Indicators)
                    {                    
                        for (int seriesCount = 0; seriesCount <  indicator.Values.Length ; seriesCount++)
                        {
                            Plot    plot                = indicator.Plots[seriesCount];
                            double val                    = indicator.Values[seriesCount].GetValueAt(index);    
                            if (indicator.Name ==Name)
                            {
                                Print (Name+"  "+MyPlot+"  "+index+" --->  "+indicator.Name+"  "+plot+"   "+val);
                            }
    
                            if (indicator.Name ==Name && plot.Name==MyPlot)
                            retour =  val;
                        }
                    }
                Print (retour);
                return retour;
            }​

    #2
    What value are you passing for index?

    Comment


      #3
      Just before calling this function, did you try calling Update first?

      Comment


        #4
        My indicator works on close.
        I use the Index like in Close[index].
        So the index is 0 for the current bar, 1 for the bar before.

        I've tried Update() but nothing changes.

        Thanks for your help

        Comment


          #5
          Are you sure you're using GetValueAt correctly?

          I kinda doubt it.

          GetValueAt uses 'absolute bar' indexes, not 'bars ago' indexes.

          Why do you care about the value of the plot on the very first
          bar of the chart -- that's what passing '0' means, right?

          Comment


            #6
            Thank you, you are right, it all comes from there!!!!
            I've corrected it and everything works great.
            ​MERCI !

            Comment


              #7
              Hello stephletrader,

              Thanks for your post.

              bltdavid has provided some great information on this topic and I am happy to hear you have resolved this.

              Keep in mind that GetValueAt() uses a barIndex value, not a barsAgo value.

              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

              Latest Posts

              Collapse

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