Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to deliver a dataseries to a method?

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

    how to deliver a dataseries to a method?

    Hello

    I want to calculate the StdDev for a customized Mean (i.e. EMA instead of SMA).
    Can anyone help me figure out how to use a dataseries (i.e. EMA(10)) within an customized StdDev-Indicator-Method without a re-calculation of that EMA in that Indicator?

    something like...

    IndicatorSeries.Set(EMA(10)[0]);

    and than...

    double EMAStddev = StdDevIND(indicatorSeries, Period)[0] ?


    What kind of Configuraton I have to use for the DataSeries in the StdDevIND - Indicator?

    The following code did not work!

    public class StdDevIND : Indicator
    {
    #region Variables
    private int period = 14;
    private DataSeries sumSeries;
    #endregion
    ....


    best
    Trendseek

    #2
    Trendseek, any indicator would implement the IDataSeries interface, meaning you can pass in a DataSeries to calculate it on - http://www.ninjatrader-support.com/H...ataSeries.html

    Comment


      #3
      Hello Bertrand,

      thanks for that fast response and the Link about using IDataSeries .
      It is Monday, and perhaps therefore I am not as clever as usual

      It wont work - obviously I forgott something:

      Error on calling 'OnBarUpdate' method for indicator 'StdDevIND' on bar 14: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.

      This is the snipped code out of the calling Object:

      Code:
      FastMA.Set(SMA(MAPeriod)[0]);
      double dStdDev        = StdDevIND(FastMA, MAPeriod)[0] ;
      ... and this is the Main-Code-Snip of the called Object (StdDevIND):

      Code:
          public class StdDevIND : Indicator
          {
              #region Variables
                  IDataSeries     IndSeries;
                  private int        period    = 14;
              
              #endregion
      
              protected override void Initialize()
              {
                  Add(new Plot(Color.Green, "StdDev"));
              }
      
              protected override void OnBarUpdate()
              {
                  if (CurrentBar < period)
                  {
                      return;
                  }
                  else
                  {
                     
                      
                      double sum = 0;
                        for (int count = 0; count < Period ; count++)
                      {
                          Print("Wert der Indikatorserie = " + IndSeries[count]);
                          double diff = Math.Abs(Input[count] - IndSeries[count]);
                          sum += diff * diff;
                      }   
      
                      Value.Set(Math.Sqrt(sum / Period));
                  }
              }
      May you have an other little Hint for me?

      Greetings to Lüneburg from Leipzig
      Trendseek

      Comment


        #4
        Thanks - the issue is likely not the calling of the indicator, but the indicator itself - what is your IndSeries exactly? I replaced it from example with this call, could compile and run it without any log issues -

        double diff = Math.Abs(Input[count] - SMA(Input, MAPeriod)[count]);

        Comment


          #5
          The Idea is simply to avoid a recalculation of the used mean!
          I already have calculate the DataSeries for that mean in the calling Object, and just want to get access to that Dataseries from within the called Object (the StdDevIND).

          An other advantage is, that i can calculate the StdDev for different means - depends from the mean, used in the calling Object.

          Comment


            #6
            Correct, the would be achieved by simply passing in the needed dataSeries to calculate on in as you call your custom StdDevInd indicator - myCustomMeanValue = StdDevIn(myCustomMeanSeries, 20)[0];

            What you would need to debug is the custom StdDevInd you try calling, as it runs into trying to access an empty object.

            Comment


              #7
              Originally posted by NinjaTrader_Bertrand View Post
              What you would need to debug is the custom StdDevInd you try calling, as it runs into trying to access an empty object.
              hmm - that was not very helpfull...
              May my Question was a little bit unclear?

              I just have a simple Question - How can I use the Values of a Dataseries (like the SMA-Values) which was calculate by one Indicator (like Bollinger) within an other Indicator (like a customized Standard Deviation) ?
              --> What kind of Declaration and Initialisation I have to use in that Case???

              May someone can give me an advice...

              Trendseek

              Comment


                #8
                trendseek, if those values are a plot they are exposed and you can directly access them from other code, like the upper band value of the Bollingers.

                If this is a non plotted, internal dataSeries, you can use this sample to expose it -

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                579 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                334 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
                554 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                551 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X