此代码的主要工作是:
获得18个不同符号的 Close
价格 - 所有主要货币对。
使用CopyClose()
函数,分成18个不同的数组。
所有18个符号都配对,每个符号组成324个阵列 (我知道伙计们,我知道,我的设计很糟糕,但我刚开始编写9月编码,这就是为什么我需要你的帮助。)
然后每个324个数组传递给 Pearson_r()
,计算彼此之间的相关性。
将相关结果分配给2D数组中的特定列和行之后。 (相关矩阵)。
我只想要一个计算所有324个成对符号Correlation的函数,然后将它存储在2D-Array的特定列和行中。
2D阵列的分配是特定的原因是因为当我搜索大于85.0的相关值时,我需要知道列和行属于哪些符号,我正在进行相关对冲EA。
这是我的:
int OnInit()
{
double audjpy_data[12];
double audusd_data[12];
double chfjpy_data[12];
double euraud_data[12];
double eurcad_data[12];
double eurchf_data[12];
double eurgbp_data[12];
double eurjpy_data[12];
double eurusd_data[12];
double gbpaud_data[12];
double gbpcad_data[12];
double gbpchf_data[12];
double gbpjpy_data[12];
double gbpusd_data[12];
double nzdjpy_data[12];
double nzdusd_data[12];
double usdcad_data[12];
double usdchf_data[12];
double usdjpy_data[12];
NormalizeDouble(CopyClose("USDCHF",PERIOD_H1,1,11,usdchf_data),8);
NormalizeDouble(CopyClose("USDJPY",PERIOD_H1,1,11,usdjpy_data),8);
NormalizeDouble(CopyClose("GBPUSD",PERIOD_H1,1,11,gbpusd_data),8);
NormalizeDouble(CopyClose("EURUSD",PERIOD_H1,1,11,eurusd_data),8);
NormalizeDouble(CopyClose("GBPJPY",PERIOD_H1,1,11,gbpjpy_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
NormalizeDouble(CopyClose("EURUSD",PERIOD_H1,1,11,eurusd_data),8);
NormalizeDouble(CopyClose("GBPJPY",PERIOD_H1,1,11,gbpjpy_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
NormalizeDouble(CopyClose("EURUSD",PERIOD_H1,1,11,eurusd_data),8);
NormalizeDouble(CopyClose("GBPJPY",PERIOD_H1,1,11,gbpjpy_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
NormalizeDouble(CopyClose("EURUSD",PERIOD_H1,1,11,eurusd_data),8);
NormalizeDouble(CopyClose("GBPJPY",PERIOD_H1,1,11,gbpjpy_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
NormalizeDouble(CopyClose("EURUSD",PERIOD_H1,1,11,eurusd_data),8);
NormalizeDouble(CopyClose("GBPJPY",PERIOD_H1,1,11,gbpjpy_data),8);
NormalizeDouble(CopyClose("USDCAD",PERIOD_H1,1,11,usdcad_data),8);
double arrayX[], arrayY[];
double arrayX_size;
double arrayY_size;
double AUDJPY_AUDUSD = 0,AUDJPY_CHFJPY = 0,
AUDJPY_EURAUD = 0,
AUDJPY_EURCAD = 0,
AUDJPY_EURCHF = 0,
AUDJPY_EURGBP = 0,
AUDJPY_EURJPY = 0,
AUDJPY_EURUSD = 0,
AUDJPY_GBPAUD = 0,
AUDJPY_GBPCAD = 0,
AUDJPY_GBPCHF = 0,
AUDJPY_GBPJPY = 0,
AUDJPY_GBPUSD = 0,
AUDJPY_NZDJPY = 0,
AUDJPY_NZDUSD = 0,
AUDJPY_USDCAD = 0,
AUDJPY_USDCHF = 0,
AUDJPY_USDJPY = 0; //18.
double AUDUSD_CHFJPY = 0,
AUDUSD_EURAUD = 0,
AUDUSD_EURCAD = 0,
AUDUSD_EURCHF = 0,
AUDUSD_EURGBP = 0,
AUDUSD_EURJPY = 0,
AUDUSD_EURUSD = 0,
AUDUSD_GBPAUD = 0,
AUDUSD_GBPCAD = 0,
AUDUSD_GBPCHF = 0,
AUDUSD_GBPJPY = 0,
AUDUSD_GBPUSD = 0,
AUDUSD_NZDJPY = 0,
AUDUSD_NZDUSD = 0,
AUDUSD_USDCAD = 0,
AUDUSD_USDCHF = 0,
AUDUSD_USDJPY = 0; //17.
double CHFJPY_EURAUD = 0,
CHFJPY_EURCAD = 0,
CHFJPY_EURCHF = 0,
CHFJPY_EURGBP = 0,
CHFJPY_EURJPY = 0,
CHFJPY_EURUSD = 0,
CHFJPY_GBPAUD = 0,
CHFJPY_GBPCAD = 0,
CHFJPY_GBPCHF = 0,
CHFJPY_GBPJPY = 0,
CHFJPY_GBPUSD = 0,
CHFJPY_NZDJPY = 0,
CHFJPY_NZDUSD = 0,
CHFJPY_USDCAD = 0,
CHFJPY_USDCHF = 0,
CHFJPY_USDJPY = 0; //16
double EURAUD_EURCAD = 0,
EURAUD_EURCHF = 0,
EURAUD_EURGBP = 0,
EURAUD_EURJPY = 0,
EURAUD_EURUSD = 0,
EURAUD_GBPAUD = 0,
EURAUD_GBPCAD = 0,
EURAUD_GBPCHF = 0,
EURAUD_GBPJPY = 0,
EURAUD_GBPUSD = 0,
EURAUD_NZDJPY = 0,
EURAUD_NZDUSD = 0,
EURAUD_USDCAD = 0,
EURAUD_USDCHF = 0,
EURAUD_USDJPY = 0; //15.
double EURCAD_EURCHF = 0,
EURCAD_EURGBP = 0,
EURCAD_EURJPY = 0,
EURCAD_EURUSD = 0,
EURCAD_GBPAUD = 0,
EURCAD_GBPCAD = 0,
EURCAD_GBPCHF = 0,
EURCAD_GBPJPY = 0,
EURCAD_GBPUSD = 0,
EURCAD_NZDJPY = 0,
EURCAD_NZDUSD = 0,
EURCAD_USDCAD = 0,
EURCAD_USDCHF = 0,
EURCAD_USDJPY = 0; //14
double EURCHF_EURGBP = 0,
EURCHF_EURJPY = 0,
EURCHF_EURUSD = 0,
EURCHF_GBPAUD = 0,
EURCHF_GBPCAD = 0,
EURCHF_GBPCHF = 0,
EURCHF_GBPJPY = 0,
EURCHF_GBPUSD = 0,
EURCHF_NZDJPY = 0,
EURCHF_NZDUSD = 0,
EURCHF_USDCAD = 0,
EURCHF_USDCHF = 0,
EURCHF_USDJPY = 0; //13.
double EURGBP_EURJPY = 0,
EURGBP_EURUSD = 0,
EURGBP_GBPAUD = 0,
EURGBP_GBPCAD = 0,
EURGBP_GBPCHF = 0,
EURGBP_GBPJPY = 0,
EURGBP_GBPUSD = 0,
EURGBP_NZDJPY = 0,
EURGBP_NZDUSD = 0,
EURGBP_USDCAD = 0,
EURGBP_USDCHF = 0,
EURGBP_USDJPY = 0; //12
double EURJPY_EURUSD = 0,
EURJPY_GBPAUD = 0,
EURJPY_GBPCAD = 0,
EURJPY_GBPCHF = 0,
EURJPY_GBPJPY = 0,
EURJPY_GBPUSD = 0,
EURJPY_NZDJPY = 0,
EURJPY_NZDUSD = 0,
EURJPY_USDCAD = 0,
EURJPY_USDCHF = 0,
EURJPY_USDJPY = 0; //11.
double EURUSD_GBPAUD = 0,
EURUSD_GBPCAD = 0,
EURUSD_GBPCHF = 0,
EURUSD_GBPJPY = 0,
EURUSD_GBPUSD = 0,
EURUSD_NZDJPY = 0,
EURUSD_NZDUSD = 0,
EURUSD_USDCAD = 0,
EURUSD_USDCHF = 0,
EURUSD_USDJPY = 0; //10.
double GBPAUD_GBPCAD = 0,
GBPAUD_GBPCHF = 0,
GBPAUD_GBPJPY = 0,
GBPAUD_GBPUSD = 0,
GBPAUD_NZDJPY = 0,
GBPAUD_NZDUSD = 0,
GBPAUD_USDCAD = 0,
GBPAUD_USDCHF = 0,
GBPAUD_USDJPY = 0; //9.
double GBPCAD_GBPCHF = 0,
GBPCAD_GBPJPY = 0,
GBPCAD_GBPUSD = 0,
GBPCAD_NZDJPY = 0,
GBPCAD_NZDUSD = 0,
GBPCAD_USDCAD = 0,
GBPCAD_USDCHF = 0,
GBPCAD_USDJPY = 0; //8.
double GBPCHF_GBPJPY = 0,
GBPCHF_GBPUSD = 0,
GBPCHF_NZDJPY = 0,
GBPCHF_NZDUSD = 0,
GBPCHF_USDCAD = 0,
GBPCHF_USDCHF = 0,
GBPCHF_USDJPY = 0; //7.
double GBPJPY_GBPUSD = 0,
GBPJPY_NZDJPY = 0,
GBPJPY_NZDUSD = 0,
GBPJPY_USDCAD = 0,
GBPJPY_USDCHF = 0,
GBPJPY_USDJPY = 0; //6.
double GBPUSD_NZDJPY = 0,
GBPUSD_NZDUSD = 0,
GBPUSD_USDCAD = 0,
GBPUSD_USDCHF = 0,
GBPUSD_USDJPY = 0; //5.
double NZDJPY_NZDUSD = 0,
NZDJPY_USDCAD = 0,
NZDJPY_USDCHF = 0,
NZDJPY_USDJPY = 0; //4.
double NZDUSD_USDCAD = 0,
NZDUSD_USDCHF = 0,
NZDUSD_USDJPY = 0; //3.
double USDCAD_USDCHF = 0,
USDCAD_USDJPY = 0; //2.
double USDCHF_USDJPY = 0; //1.
double corr_table[18][18]; //18*18 Corelation Table.
for(int counter=0; counter<31; counter++)
{
if(counter == 0)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
//Alert("badd");
}
else if(counter == 1)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 3)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 4)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 5)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 6)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 7)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 8)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 9)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 10)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 11)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 12)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 13)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 14)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 15)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 16)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 17)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 18)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 19)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 20)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 21)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 22)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 23)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 24)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 25)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 26)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 27)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 28)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter== 29)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,gbpusd_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
}
else if(counter == 30)
{
ArrayCopy(arrayX,usdchf_data,0,0,WHOLE_ARRAY);
ArrayCopy(arrayY,usdjpy_data,0,0,WHOLE_ARRAY);
arrayX_size = ArraySize(arrayX);
arrayY_size = ArraySize(arrayY);
//Alert("yessss");
}
double r = pearsons_r(arrayX,arrayY);
//Comment(r);
if(counter == 0)
{
GBPUSD_USDCHF = r;
Alert(r);
}
else if(counter == 1)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 2)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 3)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 4)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 5)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 6)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 7)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 8)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 9)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 10)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 11)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 12)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 13)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 14)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 15)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 16)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 17)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 18)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 19)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 20)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 21)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 22)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 23)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 24)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 25)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 26)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 27)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 28)
{
GBPUSD_USDCHF = r;
Comment(r);
}
else if(counter == 29)
{
USDCHF_USDJPY = r;
//Comment("yep"+r);
}
else if(counter == 30)
{
GBPUSD_USDCHF = r;
Comment(r);
}*/
corr_table[0][0] = AUDJPY_AUDUSD;
corr_table[0][1] = AUDJPY_CHFJPY;
corr_table[0][2] = AUDJPY_EURAUD;
corr_table[0][3] = AUDJPY_EURCAD;
corr_table[0][4] = AUDJPY_EURCHF;
corr_table[0][5] = AUDJPY_EURGBP;
corr_table[0][6] = AUDJPY_EURJPY;
corr_table[0][7] = AUDJPY_EURUSD;
corr_table[0][8] = AUDJPY_GBPAUD;
corr_table[0][9] = AUDJPY_GBPCAD;
corr_table[0][10] = AUDJPY_GBPCHF;
corr_table[0][11] = AUDJPY_GBPJPY;
corr_table[0][12] = AUDJPY_GBPUSD;
corr_table[0][13] = AUDJPY_NZDJPY;
corr_table[0][14] = AUDJPY_NZDUSD;
corr_table[0][15] = AUDJPY_USDCAD;
corr_table[0][16] = AUDJPY_USDCHF;
corr_table[0][17] = AUDJPY_USDJPY;
corr_table[1][0] = GBPUSD_USDCHF;
corr_table[1][1] = USDCHF_USDJPY;
corr_table[1][2] = GBPUSD_USDCHF;
corr_table[1][3] = USDCHF_USDJPY;
corr_table[1][4] = GBPUSD_USDCHF;
corr_table[1][5] = USDCHF_USDJPY;
corr_table[1][6] = GBPUSD_USDCHF;
corr_table[1][7] = USDCHF_USDJPY;
corr_table[1][8] = GBPUSD_USDCHF;
corr_table[1][9] = USDCHF_USDJPY;
corr_table[1][10] = GBPUSD_USDCHF;
corr_table[1][11] = USDCHF_USDJPY;
corr_table[1][12] = GBPUSD_USDCHF;
corr_table[1][13] = USDCHF_USDJPY;
corr_table[1][14] = GBPUSD_USDCHF;
corr_table[1][15] = USDCHF_USDJPY;
corr_table[1][16] = GBPUSD_USDCHF;
corr_table[1][17] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
corr_table[0][1] = GBPUSD_USDCHF;
corr_table[0][2] = USDCHF_USDJPY;
}
return(INIT_SUCCEEDED);
}
double pearsons_r(double &dataX[],double &dataY[])
{
double sumX = 0,sumY = 0;
double meanX = 0,meanY = 0;
double sumXY = 0;
double sumX2 = 0,sumY2 = 0;
double dev_x[12],dev_y[12];
double dev_xy[12];
double size_dataX = ArraySize(dataX);
double size_dataY = ArraySize(dataY);
//Alert(size_dataX);
for(int jj = 0; jj<size_dataX; jj++)
{
sumX += dataX[jj];
sumY += dataY[jj];
//Alert(sumY);
}
meanX = sumX / size_dataX;
meanY = sumY / size_dataY;
//Alert(meanY);
for(int jj = 0; jj<size_dataX; jj++)
{
dev_x[jj] = dataX[jj] - meanX;
dev_y[jj] = dataY[jj] - meanY;
//Alert(dev_x[5]);
dev_xy[jj] = dev_x[jj] * dev_y[jj];
//Comment(dev_xy[3]);
sumX2 += dev_x[jj] * dev_x[jj];
//Comment(sumX2);
sumY2 += dev_y[jj] * dev_y[jj];
//Comment(sumX2);
sumXY += dev_x[jj] * dev_y[jj];
//Comment(sumXY);
}
double lower_half = sumX2 * sumY2;
double final_lower_half = sqrt(lower_half);
//Comment(final_lower_half);
double correlation = NormalizeDouble(sumXY / final_lower_half,2);
//Comment(correlation);
correlation = correlation*100;
Comment(correlation);
return (correlation);
}
答案 0 :(得分:0)
什么是问题?除了在这里提出多个类似的问题之外,使用2D数组的简单方法有什么问题?
也许这会有所帮助:
const string allSymbols[18] = {"EURUSD","USDJPY", };//all 18 your symbols
int SIZE = ArraySize(allSymbols);
void Function(){
double correlationMatrix[18][18];
for(int i=0; i<SIZE; i++){
for(int j=0; j<SIZE; j++){
if (i==j) continue;
double correlation = Pearson_r_calc(allSymbols[i],allSymbols[j]);
correlationMatrix[i][j] = correlation;
//process your matrix further, 'ij' is a correlation of i and j symbols
}
}
}
double Pearson_r_calc(const string symb1,const string symb2){
double array1[],array2[];
CopyClose(symb1,PERIOD_H1,1,11,array1); //1 and 11 are your numbers
CopyClose(symb2,PERIOD_H1,1,11,array2);
return pearson_r(array1,array2); //pearson_r(string,string) is your fn.
}