public static double Correlation(this double[] x, double[] y, int n)public double Correlation(double[] x, double[] y, int n)
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators;namespace WealthLab.Strategies { public class CorrelationDemo : WealthScript { protected override void Execute() { // How well correlated were CMO and RSI? int n = Bars.Count; double[] x = new double[n]; double[] y = new double[n]; RSI rsi = RSI.Series( Close, 20 ); CMO cmo = CMO.Series( Close, 20 ); for(int bar = 0; bar < Bars.Count; bar++) { x[bar] = rsi[bar]; y[bar] = cmo[bar]; } DrawLabel( PricePane, "Correlation: " + x.Correlation( y, n ) ); } } }
using System; using System.Collections.Generic; using System.Text; using System.Drawing; using WealthLab; using WealthLab.Indicators; using Community.Components; // Correlation herenamespace WealthLab.Strategies { public class CorrelationDemo : WealthScript { protected override void Execute() { // How well correlated were CMO and RSI? int n = Bars.Count; double[] x = new double[n]; double[] y = new double[n]; RSI rsi = RSI.Series( Close, 20 ); CMO cmo = CMO.Series( Close, 20 ); for(int bar = 0; bar < Bars.Count; bar++) { x[bar] = rsi[bar]; y[bar] = cmo[bar]; } Calculate calc = new Calculate(this); // pass WealthScript DrawLabel( PricePane, "Correlation: " + calc.Correlation( x, y, n ) ); } } }