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 CarlTrading, 05-11-2026, 05:56 AM
          0 responses
          27 views
          0 likes
          Last Post CarlTrading  
          Started by CarlTrading, 05-10-2026, 08:12 PM
          0 responses
          20 views
          0 likes
          Last Post CarlTrading  
          Started by Hwop38, 05-04-2026, 07:02 PM
          0 responses
          183 views
          0 likes
          Last Post Hwop38
          by Hwop38
           
          Started by CaptainJack, 04-24-2026, 11:07 PM
          0 responses
          335 views
          0 likes
          Last Post CaptainJack  
          Started by Mindset, 04-21-2026, 06:46 AM
          0 responses
          260 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Working...
          X