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

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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by maybeimnotrader, Yesterday, 05:46 PM
          5 responses
          24 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by NRITV, Today, 01:15 PM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by quantismo, Yesterday, 05:13 PM
          2 responses
          16 views
          0 likes
          Last Post quantismo  
          Started by frankthearm, Today, 09:08 AM
          6 responses
          27 views
          0 likes
          Last Post frankthearm  
          Started by adeelshahzad, Today, 03:54 AM
          5 responses
          33 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X