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

DataSeries objects

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

    DataSeries objects

    I just read the Level 4 Turorial on Historical Custom Data Series and read the DataSeries class definition in the help guide. Very helpful.

    I come from the land of Tradestation (I know YUCK!), and I'm used to all variables that you declare automatically being declared for you as having series history.

    Am I correct in assuming that the DataSeries object is just an ever-expanding array of a data series so that you can reference any (double) calculation historically?

    TS:
    var: myDouble(0);
    myDouble = High - Low;

    NinjaTrader:
    //does not change with bar history--- not an array
    double myDouble = 0;

    //changes with series history so you can reference a calc historically?
    DataSeries myDataSeries;
    protected override void Intialize()
    {
    myDataSeries = new DataSeries(this)
    }
    protected override void OnBarUpdate()
    {
    myDataSeries.Set(High[0] - Low[0]);
    if (myDataSeries[5] > 2.0) //CAN REFERENCE HISTORICALLY NOW!
    {
    //do something
    }
    }

    In the above example and in the user guide it says I can reference the myDataSeries DataSeries object with the [] brackets. However, the user guide says something about Value and Values properties / collections. When and/or how would I use those in code?


    Thank you!
    Attached Files
    Last edited by geoMEAN; 04-21-2008, 01:38 AM. Reason: adding more info

    #2
    The way you have it done should work perfectly.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Oops sorry, I just added my main question to the thread bolded and underlined. You were too quick to respond!

      Comment


        #4
        Hmm. Take a look at the SMA indicator for an example of how they are used. Generally you don't need to worry too much about them. If you create a DataSeries object you will never go wrong just calling the DataSeries' name.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          FINALLY I think I understand something!!! YAY!

          Code:
          protected override void OnBarUpdate()
                  {
                      if (CurrentBar == 0)
                          Value.Set(Input[0]);
                      else
                      {
                          double last = Value[1] * Math.Min(CurrentBar, Period);
          
                          if (CurrentBar >= Period)
                              Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
                          else
                              Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
                      }
                  }
          Let's see if I have this straight. In above code, "Input[0]" keyword represents whichever time series I'm feeding the Indicator (e.g. O,H,L,C history), whereas "Value[1]" refers to the Indicator itself (the SMA) one bar ago.

          Clarification question: I assume that in the case of the SMA, where the "value" keyword is being used to refer to the SMA indicator itself, you wouldn't be able to use SMA[1] as a replacement. Correct?

          I believe I have it now!

          FYI, one thing that is confusing coming from Tradestation to Ninjatrader is that in Tradestation "Indicators" are scripts that CAN ONLY BE APPLIED TO CHARTS. THEY ARE NOT FUNCTIONS/METHODS. They do nothing except plot stuff. So once I came to the realization that indicators in NT act both as plotting scripts and method/function scripts, callable from other ninjascripts, I understood how things were working in NT a lot better.

          Comment


            #6
            Excellent -

            - Correct, you can't use SMA[1]
            - Value is referring to the internal DataSeries objects that holds the indicator values that are used for plotting (think of an array of indicator values for each bar on a chart)
            - Your understanding of Input is correct
            RayNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Haiasi, 04-25-2024, 06:53 PM
            2 responses
            16 views
            0 likes
            Last Post Massinisa  
            Started by Creamers, Today, 05:32 AM
            0 responses
            4 views
            0 likes
            Last Post Creamers  
            Started by Segwin, 05-07-2018, 02:15 PM
            12 responses
            1,785 views
            0 likes
            Last Post Leafcutter  
            Started by poplagelu, Today, 05:00 AM
            0 responses
            3 views
            0 likes
            Last Post poplagelu  
            Started by fx.practic, 10-15-2013, 12:53 AM
            5 responses
            5,407 views
            0 likes
            Last Post Bidder
            by Bidder
             
            Working...
            X