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

accessing indicators

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

    accessing indicators

    I am trying to access various indicators values at various bars but having trouble.

    protected override void OnBarUpdate()

    double x = SuperTrend(14,2.618)[0];


    if (
    SuperTrend(14,2.618)[0] < Close[0] <-- This Works
    x < Close[0] <-- This Works
    x[1] < Close[0] <--- This does NOT work
    )

    Question: How do I access various bars back in brackets once the indicator is named as above?

    Another example of what I want to do:

    x[1] > x[5]

    thanks

    #2
    Originally posted by velocity View Post
    I am trying to access various indicators values at various bars but having trouble.

    protected override void OnBarUpdate()

    double x = SuperTrend(14,2.618)[0];


    if (
    SuperTrend(14,2.618)[0] < Close[0] <-- This Works
    x < Close[0] <-- This Works
    x[1] < Close[0] <--- This does NOT work
    )

    Question: How do I access various bars back in brackets once the indicator is named as above?

    Another example of what I want to do:

    x[1] > x[5]

    thanks
    In order to do that x must be DataSeries and you have it as double

    Comment


      #3
      Thanks for responding.

      I changed it to DataSeries and did the following:

      public class Triggers : Indicator
      {
      #region Variables
      private DataSeries myDataSeries;
      #endregion

      protected override void OnBarUpdate()
      {
      myDataSeries = new DataSeries(SuperTrend(14,2.618));

      if (
      SuperTrend(14,2.618)[0] < Close[0] <--- This Works

      myDataSeries[0] < Close[0] <-- This does not work


      Any ideas?
      Last edited by velocity; 02-21-2009, 06:23 PM.

      Comment


        #4
        This is not how you define a dataseries. Try this:

        private DataSeries x; <- goes in Variables area

        x = new DataSeries(this); <- goes after added plots in Initialize() area

        x.Set(SuperTrend(14,2.618)[0]); <-- in code after OnBarUpdate()

        x[1] < Close[0]
        eDanny
        NinjaTrader Ecosystem Vendor - Integrity Traders

        Comment


          #5
          I must be doing something wrong. Lets say i have the following:

          private DataSeries cci_data; <-- in #region Variables

          cci_data = new DataSeries(this); <-- in protected override void Initialize()

          cci_data.Set(CCI(14)[0]); <-- in protected override void OnBarUpdate()

          if(

          cci_data[0] > 100 <-- this works
          cci_data[1] > 100 <-- this does NOT work

          Where am I going wrong?

          Comment


            #6
            Hello,

            Sorry to jump in here but this may help.

            It should work, unless there is some other issue causing it not to work. You may want to paste in all of the code that is affected so we can test it for you and help you further.

            Remember this [1] accesses a value one bar back, not the value that was stored previously. In other words, there is only one value stored per bar for each DataSeries.

            Sorry if you already know this...
            DenNinjaTrader Customer Service

            Comment


              #7
              thank you Ben, I think I got it. I inserted

              if (CurrentBar < 10)
              return;

              and now if I want to go back up to 10 bars i can do up to cci_data[10] Right?

              with out inserting above code I could only access current bar. Right?
              Last edited by velocity; 02-22-2009, 11:25 AM.

              Comment


                #8
                Hello,

                Yes, you can now reference up to 10 bars back.
                DenNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by cre8able, Yesterday, 04:22 PM
                1 response
                13 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by stafe, 04-15-2024, 08:34 PM
                5 responses
                28 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by StrongLikeBull, Yesterday, 04:05 PM
                1 response
                12 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by Mestor, 03-10-2023, 01:50 AM
                14 responses
                375 views
                0 likes
                Last Post z.franck  
                Started by molecool, 10-09-2017, 10:48 AM
                5 responses
                1,621 views
                0 likes
                Last Post trader-ap  
                Working...
                X