• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to do a modification to the StdDev() function?

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

    How to do a modification to the StdDev() function?

    I'm currently making a modification to the StdDev() function, calling it StdDevPlus(). Right now, StdDev() can take one input data series and a period. I want it to take 2 input data series, with the 2nd series being a moving average of my choice which will be used in the calculation of the standard deviation.

    The relevant section of code for StdDev() is here:

    protected override void OnBarUpdate()
    {
    if (CurrentBar < 1)
    {
    Value.Set(0);
    sumSeries.Set(Input[0]);
    }
    else
    {
    sumSeries.Set(Input[0] + sumSeries[1] - (CurrentBar >= Period ? Input[Period] : 0));
    double avg = sumSeries[0] / Math.Min(CurrentBar + 1, Period);
    double sum = 0;
    for (int barsBack = Math.Min(CurrentBar, Period - 1); barsBack >= 0; barsBack--)
    sum += (Input[barsBack] - avg) * (Input[barsBack] - avg);

    Value.Set(Math.Sqrt(sum / Math.Min(CurrentBar + 1, Period)));
    }
    }

    The bolded section is the section I want to change. Rather than using the calculated simple average, I want to pass the average from a series (like TEMA) and use that value.

    Let's say the second input is called Input2. So the bolded section would now look like this:

    sum += (Input[barsBack] - input2[barsBack]) * (Input[barsBack] - input2[barsBack]);

    What I can't figure out is to how to have an iDataSeries object passed as input2 as an argument in the function and then use it in this manner.


    Here's an example of MLQ4 code that does this and I'm trying to do the 2nd option:


    //
    //
    //
    // In the original article the second method is how deviation is
    // calculated . It is a questionableble method , but if we apply
    // standard calculation the bands tend to be "spiky".That is the
    // reason to have the "UseClassicalDeviations" option
    //
    //
    //

    double iDeviationPlus(double& array[], double& ma[], int period, int i)
    {
    double sum = 0;
    if (UseClassicalDeviations)
    for(int k=0; k<period; k++) sum += (array[i+k]-ma[i]) *(array[i+k]-ma[i]);
    else for( k=0; k<period; k++) sum += (array[i+k]-ma[i+k])*(array[i+k]-ma[i+k]);
    return(MathSqrt(sum/period));
    }

    #2
    I've also tried just to get the standard deviation of the zero lag TEMA indicator (posted in a recent thread) using the StdDev function but I get an error message when I try to compile.

    double stdDevValue = StdDev(ZeroLagTEMA, Period)[0];

    ...gives me two compiling error messages CS1502 and NT1503

    Argument 1 cannot convert from 'method group' to NinjaTrader.Data.IDataSeries

    Comment


      #3
      Hello,
      Thank you for your post.
      What you are wanting to do would be possible through using enumerations. We actually have a reference file on creating a moving average indicator that allows you to select different moving average. You would be able to add this into your StdDev indicator. Please see the reference at the following link,

      http://ninjatrader.com/support/forum...ead.php?t=3420


      The compiler error that you are receiving is because you will need to define a period for the ZeroLagTEMA and enter in its overloads.
      Cody B.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by YngvaiMalmsteve View Post
        I've also tried just to get the standard deviation of the zero lag TEMA indicator (posted in a recent thread) using the StdDev function but I get an error message when I try to compile.

        double stdDevValue = StdDev(ZeroLagTEMA, Period)[0];

        ...gives me two compiling error messages CS1502 and NT1503

        Argument 1 cannot convert from 'method group' to NinjaTrader.Data.IDataSeries

        You cannot call the ZerolagTEMA without parameters. The correct syntax would be one of

        Code:
        double stdDevValue = StdDev(ZeroLagTEMA (temaPeriod), stdDevPeriod)[0];
        double stdDevValue = StdDev(ZeroLagTEMA (Input, temaPeriod), stdDevPeriod)[0];
        where temaPeriod is the period selected for the ZeroLagTEMA, and stdDevPeriod is the period selected for the standard deviation.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by lavalampmj, Today, 05:25 PM
        0 responses
        1 view
        0 likes
        Last Post lavalampmj  
        Started by Antares66, Today, 05:19 PM
        0 responses
        2 views
        0 likes
        Last Post Antares66  
        Started by jmneto, Today, 05:18 PM
        0 responses
        2 views
        0 likes
        Last Post jmneto
        by jmneto
         
        Started by Bobbyj78, Today, 02:21 PM
        2 responses
        12 views
        0 likes
        Last Post bltdavid  
        Started by EnveousColnago, Today, 02:10 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Ariana  
        Working...
        X