Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Correlation

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

    Correlation

    Is there a function I can use to calculate the correlation of 2 series?
    If not has anyone written a correlation function and is happy to share?

    #2
    Unfortunately not supplied by NT.
    RayNinjaTrader Customer Service

    Comment


      #3
      I actually found a nice simple piece of C# code on Correlation which I just used.

      Comment


        #4
        Originally posted by jerrylee View Post
        I actually found a nice simple piece of C# code on Correlation which I just used.

        http://www.codeproject.com/KB/cs/Statistics.aspx
        This is the code snippet from the link: public static void GetCorrelation( double[] x, double[] y, ref double covXY, ref double pearson) { if ( x.Length != y.Length ) throw new Exception(&quot;Length of sources is different&quot; double avgX = GetAverage( x ); double stdevX = GetStdev( x ); double avgY = GetAverage( y ); double stdevY = GetStdev( y ); int len = x.Length; for ( int i = 0; i < len; i++ ) covXY += ( x[i] - avgX ) * ( y[i] - avgY ); covXY /= len; pearson = covXY / ( stdevX * stdevY ); } } } I am just learning some C#/NinjaT and can't locate the place to insert this code. I tried where there were similar types of code blocks, but when I compile the inserted code is automatically removed. Other locations produced compile errors. Could someone point out where this should be placed to compile properly?
        Last edited by marketmasher; 03-11-2009, 07:14 AM.

        Comment


          #5
          You want to create a new indicator with this you can then call from strategies or you add this to the 'user defined methods' cs for future reference.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          569 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
          548 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