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

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
    BertrandNinjaTrader Customer Service

    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]);
        BertrandNinjaTrader Customer Service

        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.
            BertrandNinjaTrader Customer Service

            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 -

                BertrandNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by judysamnt7, 03-13-2023, 09:11 AM
                4 responses
                57 views
                0 likes
                Last Post DynamicTest  
                Started by ScottWalsh, Today, 06:52 PM
                4 responses
                36 views
                0 likes
                Last Post ScottWalsh  
                Started by olisav57, Today, 07:39 PM
                0 responses
                7 views
                0 likes
                Last Post olisav57  
                Started by trilliantrader, Today, 03:01 PM
                2 responses
                19 views
                0 likes
                Last Post helpwanted  
                Started by cre8able, Today, 07:24 PM
                0 responses
                9 views
                0 likes
                Last Post cre8able  
                Working...
                X