Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Assigning values from a method to a dataseries or array

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

    Assigning values from a method to a dataseries or array

    Hi,
    I have created a simple function (method) that retruns the double value of a fast moving EMA when it crosses a slower Simple Moving Average. Lets assume this method is named Crossover()
    What I now need to do is somehow assign the values of Crossover() as they are occuring into some sort of dataseries or array so that can be called on in a strategy in a systematic fashion, e.g
    If (Crossover() [1] < Crossover() [2])
    {
    Go Long
    }

    My question is how do you assign values from a method to a dataseries or array so that they can be called up from historical data numbering from [0] current value generated by method to [1] last value to[2] second last value and so on....
    I would like the assigning to the dataseries or array to commence an hour before the start of the trading day and to end at the close of the trading day.

    #2
    jeddy0510, I suggest you check into this sample to see how to create and set custom dataeseries objects holding your double values so they could be accessed historically as well in your code:

    Comment


      #3
      Thank you so much!

      Comment


        #4
        Assigning values from a method to a dataseries or array

        Bertrand,
        I assign values to the array with DataSeries.Set(). But when I try to "Print" or "Get" a value other than index 0, (DataSeries[0]), i.e. DataSeries[1], DataSeries[2]..., etc. Those other indexed places of the array do not have any values (zero)... Please help.
        It seems that the values are not saved in the array. Is this because of OnBarUpdate?

        *****Update*******
        Just solved it. The steps are basically:

        1) Declare the variable (data structure) DataSeries:
        private DataSeries xData;

        2) Initialize the variable DataSeries:
        xData = new DataSeries(this);

        3) Assign the values (with your logic) using DataSeries.Set():
        xData.Set(xData[1] - yData[1]);

        4) Print/Plot them:
        Print("xData = " + xData[0].ToString());
        Plot0.Set(xData[0]);
        Last edited by carlosavellan; 08-29-2014, 08:15 PM.

        Comment


          #5
          Hello carlosavellan,

          Thank you for posting and thank you for the update.

          Glad you were able to resolve it.

          Let me know if I can be of further assistance.
          Cal H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          566 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          330 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          547 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          548 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X