//+------------------------------------------------------------------+ //| correlations between Pair1 and Pair2 and between Pair3 and Pair4 | //| | //+------------------------------------------------------------------+ #property copyright " " #property indicator_separate_window #property indicator_buffers 2 #property indicator_color1 Red #property indicator_color2 Yellow extern int R_Period=20; extern string Pair1="GBPJPY"; extern string Pair2="USDJPY"; extern string Pair3="GBPJPY"; extern string Pair4="GBPUSD"; double R[],Ra[]; double X[],Y[],A[],B[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators //---- drawing settings IndicatorShortName(Pair1+"/"+Pair2+" R("+R_Period+")"); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,R); SetIndexStyle(1,DRAW_LINE); SetIndexBuffer(1,Ra ); //SetIndexStyle(2,DRAW_LINE); //SetIndexBuffer(2,P ); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- double X[],Y[]; int piir, limit, omega ; double sumxy, sumx, sumx2, sumy, sumy2,sumxya, sumxa, sumx2a, sumya, sumy2a; double yks, kaks, kolm,yksa, kaksa, kolma; limit=Bars-counted_bars; //always just 1 bar after first calculation if(counted_bars==0) limit=Bars-R_Period-1; //first time it should be enough bars to calculate ArrayResize(X,limit); // min size of array is using less memory ArrayResize(Y,limit); ArrayResize(A,limit); // min size of array is using less memory ArrayResize(B,limit); ArrayCopySeries(X,MODE_OPEN,Pair1,0); ArrayCopySeries(Y,MODE_OPEN,Pair2,0); ArrayCopySeries(A,MODE_OPEN,Pair3,0); ArrayCopySeries(B,MODE_OPEN,Pair4,0); omega=0; while(omega<=limit) { sumxy=0; sumx=0; sumx2=0; sumxya=0; sumxa=0; sumx2a=0; sumy=0; sumy2=0; sumya=0; sumy2a=0; for(int i=1; i<=R_Period; i++) { sumxy+=X[omega+i]*Y[omega+i]; sumxya+=A[omega+i]*B[omega+i]; sumx+=X[omega+i]; sumxa+=A[omega+i]; sumx2+=MathPow(X[omega+i],2.); sumx2a+=MathPow(A[omega+i],2.);//2. is neccesary because MathPow wants both parts as double sumy+=Y[omega+i]; sumya+=B[omega+i]; sumy2+=MathPow(Y[omega+i],2.); sumy2a+=MathPow(B[omega+i],2.);//but it seems to work with "2" as well } yks=sumxy-(sumx*sumy)/R_Period; yksa=sumxya-(sumxa*sumya)/R_Period; kaks=sumx2-(MathPow(sumx,2.)/R_Period); kaksa=sumx2a-(MathPow(sumxa,2.)/R_Period); kolm=sumy2-(MathPow(sumy,2.)/R_Period); kolma=sumy2a-(MathPow(sumya,2.)/R_Period); R[omega]=(yks/MathSqrt(kaks*kolm)); Ra[omega]=(yksa/MathSqrt(kaksa*kolma)); omega++; } //---- return(0); } //+------------------------------------------------------------------+
Sample
Analysis
Market Information Used:
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Custom Indicators Used:
Order Management characteristics:
Other Features: