Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volatility and Standard Deviation

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

    Volatility and Standard Deviation

    I am attempting to program an historical volatility measure but am unable to resolve problems of data type and series. Affected coding is as follows.

    protected override void OnBarUpdate()
    {
    // Use this method for calculating your indicator values.

    double mLog1 = Close [0] / Close [1]; // works fine
    double mLog2 = Math.Log(mLog1); // works fine
    double mSqrt = Math.Sqrt(365)*100; // works fine

    double test = StdDev(mLog2,100) [0] * mSqrt;
    // mLog2 type and series are the problems I cannot fix

    Plot0.Set(test);

    }

    I appreciate your help.

    Andrew

    #2
    Hi Andrew,

    mLog2 needs to be a DataSeries, not a double.

    VT

    edit to expand:

    in Variable region add:
    private DataSeries mLog2;

    in Initialize() add:
    mLog2 = new DataSeries(this);

    in OnBarUpdate() define mLog2 using the Set method:
    mLog2.Set(Math.Log(mLog1));
    Last edited by VTtrader; 11-19-2011, 01:53 PM.

    Comment


      #3
      Volatility and Standard Deviation

      Thanks for your quick reply.

      I recognize that mLog2 needs to be a DataSeries, not a double. But I'm just new enough to NinjaTrader scripting to not know how to correct the problem. Could you explain in greater detail or refer me to an appropriate reference?

      Thank you,

      Andrew

      Comment


        #4
        Did you see my edit? If you need more help let me know.

        VT

        Comment


          #5
          Whoops. I see that you've already explained how to handle the problem.

          Thanks again,

          Andrew

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          637 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          366 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          107 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          569 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          571 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X