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

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
              Brandon H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by burtoninlondon, Today, 12:38 AM
              0 responses
              10 views
              0 likes
              Last Post burtoninlondon  
              Started by AaronKoRn, Yesterday, 09:49 PM
              0 responses
              14 views
              0 likes
              Last Post AaronKoRn  
              Started by carnitron, Yesterday, 08:42 PM
              0 responses
              11 views
              0 likes
              Last Post carnitron  
              Started by strategist007, Yesterday, 07:51 PM
              0 responses
              13 views
              0 likes
              Last Post strategist007  
              Started by StockTrader88, 03-06-2021, 08:58 AM
              44 responses
              3,983 views
              3 likes
              Last Post jhudas88  
              Working...
              X