//+——————————————————————+
//| 饰行潘咧冗.mq4 |
//| Copyright 2012, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+——————————————————————+
#property copyright “Copyright 2012, MetaQuotes Software Corp.”
#property link “http://www.metaquotes.net”
#property indicator_chart_window
extern int CorPeriod_1 = 120; // 镥痂钿 暑痧咫鲨?1
extern int CorPeriod_2 = 480; // 镥痂钿 暑痧咫鲨?2
extern double KK_level = 0.80; // 箴钼屙?适
extern int ControlBars = 50; // 觐腓麇耱忸 徉痤?潆 疣聍弪?腻朦螓
extern int Delta_level = 500; // 觐腓麇耱忸 徉痤?潆 疣聍弪?腻朦螓
extern bool DisplayInfo = true;
//+——————————————————————+
string Index[8]; // 怦?桧溴犟?忄膻?
string Symbols[8,8]; // 怦?铖眍忭 镟瘥 忄膻?
string Object_y[28]; // 镟瘥 潆 蜞犭桷?镱 铖?Y
string Object_x[28]; // 镟瘥 潆 蜞犭桷?镱 铖?X
string Sym_sym[28,28];// 怦?相瘥 相?(舷)
double Corr[28,28]; // 怦?暑翳鲨屙螓 暑痧咫鲨?(适)
int DIST_y[28]; // 觐铕滂磬螓 镱 铖?Y
int DIST_x[28]; // 觐铕滂磬螓 镱 铖?X
string Delte[201]={“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””}; // 爨耨桠 腻腧?
string DelteText[201]={“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,
“”,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””,””};// 爨耨桠 腻腧?耔焘铍钼
//+——————————————————————+
color Color = DodgerBlue;
int x=10,y=8,o,font_size=8,tic=20;
int CorPeriod;
int dx,dy;
//+——————————————————————+
//| expert initialization function |
//+——————————————————————+
int init()
{
//—-
o=0;
//+——————————————————————+
Index[0]=”JPY”;
Index[1]=”CHF”;
Index[2]=”CAD”;
Index[3]=”USD”;
Index[4]=”NZD”;
Index[5]=”AUD”;
Index[6]=”GBP”;
Index[7]=”EUR”;
//+——————————————————————+
for(int i=1;i<8;i++)
{
for(int j=0;j<i;j++)
{
Symbols[i,j] = StringConcatenate(Index[i],Index[j]); // 纛痨桊钼囗桢 爨耨桠?Symbols[i,j]
Object_y[o] = Symbols[i,j]; // 镳桉忸屙桢 爨耨桠?Object_y[o]
Object_x[o] = StringConcatenate(Symbols[i,j],”+”); // 镳桉忸屙桢 爨耨桠?Object_x[o]
DIST_y[o] = ((font_size+8)*28)+y-10-(font_size+6)*o; // 纛痨桊钼囗桢 爨耨桠?DIST_y[o]
DIST_x[o] = (x+font_size*8)+(font_size*4)*o; // 纛痨桊钼囗桢 爨耨桠?DIST_x[o]
//—-
ObjectCreate(Object_y[o], OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(Object_y[o], OBJPROP_CORNER, 2); // 橡桠珀?筱铍
ObjectSet(Object_y[o], OBJPROP_XDISTANCE, x); // 暑铕滂磬蜞 ?
ObjectSet(Object_y[o], OBJPROP_YDISTANCE, DIST_y[o]);// 暑铕滂磬蜞 Y
ObjectSetText(Object_y[o],Symbols[i,j],font_size,”Arial”,Color);// 如戾礤龛?疋铋耱?钺牝?
//—-
ObjectCreate(Object_x[o], OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(Object_x[o], OBJPROP_CORNER, 2); // 橡桠珀?筱铍
ObjectSet(Object_x[o], OBJPROP_ANGLE, 90); // 朽玮铕铗 蝈犟蜞 磬 筱铍
ObjectSet(Object_x[o], OBJPROP_XDISTANCE,18+DIST_x[o]);// 暑铕滂磬蜞 ?
ObjectSet(Object_x[o], OBJPROP_YDISTANCE, y); // 暑铕滂磬蜞 Y
ObjectSetText(Object_x[o],Symbols[i,j],font_size,”Arial”,Color);// 如戾礤龛?疋铋耱?钺牝?
//+——————————————————————+
o++;
}
}
return(0);
}
//+——————————————————————+
//| expert deinitialization function |
//+——————————————————————+
int deinit()
{
//—-
for(int i=0;i<28;i++)
{
if(Object_y[i]!=””)
ObjectDelete(Object_y[i]); // 愉嚯屙桢 钺牝?
if(Object_x[i]!=””)
ObjectDelete(Object_x[i]); // 愉嚯屙桢 钺牝?
}
//—-
for(int t=1;t<28;t++)
{
for(int c=0;c<t;c++)
{
if(Sym_sym[t,c]!=””)
ObjectDelete(Sym_sym[t,c]); // 愉嚯屙桢 钺牝?
}
}
//—-
ObjectDelete(“Info”); // 愉嚯屙桢 钺牝?
ObjectDelete(“Info_1″); // 愉嚯屙桢 钺牝?
//—-
for(int d=0;d<201;d++)
{
if(Delte[d]!=””)
ObjectDelete(Delte[d]); // 愉嚯屙桢 钺牝?
if(DelteText[d]!=””)
ObjectDelete(DelteText[d]); // 愉嚯屙桢 钺牝?
}
//—-
return(0);
}
//+——————————————————————+
//| expert start function |
//+——————————————————————+
int start()
{
//—-
//+——————————————————————+
if(tic<5){tic++;return(0);}
else tic=0;
//+——————————————————————+
for(int d=0;d<201;d++)
{
if(Delte[d]!=””)
ObjectDelete(Delte[d]); // 愉嚯屙桢 钺牝?
if(DelteText[d]!=””)
ObjectDelete(DelteText[d]); // 愉嚯屙桢 钺牝?
}
//+——————————————————————+
o=0;int o_1=0;dx=0;dy=0;
string Text;
for(int a=1;a<28;a++)
{
for(int b=0;b<a;b++)
{
Sym_sym[a,b] = StringConcatenate(Object_y[a],”_”,Object_y[b]);
//—-
CorPeriod = CorPeriod_1;
double C = Cor(Object_y[a], Object_y[b]);
Text = DoubleToStr(C,2);
Color = DimGray;
if(C>=KK_level)
{
Color = Yellow;o++;
CorPeriod = CorPeriod_2;
C = Cor(Object_y[a], Object_y[b]);
if(C>=KK_level){Object(0,a,b,o_1);Color = Lime;o_1++;}
}
if(C<=-KK_level)
{
Color = Yellow;o++;
CorPeriod = CorPeriod_2;
C = Cor(Object_y[a], Object_y[b]);
if(C<=-KK_level){Object(1,a,b,o_1);Color = Red;o_1++;}
}
ObjectCreate(Sym_sym[a,b], OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(Sym_sym[a,b], OBJPROP_CORNER, 2); // 橡桠珀?筱铍
ObjectSet(Sym_sym[a,b], OBJPROP_XDISTANCE, DIST_x[b]); // 暑铕滂磬蜞 ?
ObjectSet(Sym_sym[a,b], OBJPROP_YDISTANCE, DIST_y[a]);// 暑铕滂磬蜞 Y
ObjectSetText(Sym_sym[a,b],Text,font_size,”Arial”,Color);// 如戾礤龛?疋铋耱?钺牝?
//—-
}
}
//—-
//————————————————————— 2 —
if (DisplayInfo)
{
Color = Yellow;
Text = StringConcatenate(” KK period I = “,DoubleToStr(CorPeriod_1,0),” KK level = “,DoubleToStr(KK_level, 2),” Total III= “,DoubleToStr(o, 0));
ObjectCreate(“Info”, OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(“Info”, OBJPROP_CORNER, 0); // 橡桠珀?筱铍
ObjectSet(“Info”, OBJPROP_XDISTANCE, 10);// 暑铕滂磬蜞 ?
ObjectSet(“Info”, OBJPROP_YDISTANCE, 15);// 暑铕滂磬蜞 Y
ObjectSetText(“Info”,Text,12,”Arial”,Color);// 如戾礤龛?疋铋耱?钺牝?
//————————————————————— 3 —
//————————————————————— 2 —
Color = Yellow;
Text = StringConcatenate(” KK Period II = “,DoubleToStr(CorPeriod_2,0),” Delta bars= “,DoubleToStr(ControlBars, 0),” Total III 2 = “,DoubleToStr(o_1, 0));
ObjectCreate(“Info_1”, OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(“Info_1”, OBJPROP_CORNER, 0); // 橡桠珀?筱铍
ObjectSet(“Info_1”, OBJPROP_XDISTANCE, 10);// 暑铕滂磬蜞 ?
ObjectSet(“Info_1”, OBJPROP_YDISTANCE, 35);// 暑铕滂磬蜞 Y
ObjectSetText(“Info_1″,Text,12,”Arial”,Color);// 如戾礤龛?疋铋耱?钺牝?
}
//————————————————————— 3 —
//—-
// WindowRedraw();
//—-
return(0);
}
//+——————————————————————+
//+——————————————————————+
//| 饰行潘咧冗 |
//+——————————————————————+
double symboldif(string symbol, int shift)
{
return(iClose(symbol, 0, shift) –
iMA(symbol, 0, CorPeriod, 0, MODE_SMA,
PRICE_CLOSE, shift));
}
//+——————————————————————+
//| |
//+——————————————————————+
double powdif(double val)
{
return(MathPow(val, 2));
}
//+——————————————————————+
//| |
//+——————————————————————+
double u(double val1,double val2)
{
return((val1*val2));
}
//+——————————————————————+
//| 骂?磬耱? 觐痧咫鲨铐磬 趔黻鲨, 觐蝾痼?眢骓?恹玮囹? |
//+——————————————————————+
double Cor(string base, string hedge)
{
double u1=0,l1=0,s1=0;
for(int i = CorPeriod – 1; i >= 0; i–)
{
u1 += u(symboldif(base, i), symboldif(hedge, i));
l1 += powdif(symboldif(base, i));
s1 += powdif(symboldif(hedge, i));
}
if(l1*s1 > 0)
return(u1 / MathSqrt(l1*s1));
return(0);
}
//+——————————————————————+
//| 朽聍弪 蝈牦?腻朦螓, ?镳铟屙蜞? |
//+——————————————————————+
double Delta(string simbol_1, string simbol_2, bool simrev_2)
{
//—- 疣聍弪 溧眄
double arr_delta =0;
double P_1=MarketInfo(simbol_1,MODE_POINT);
double P_2=MarketInfo(simbol_2,MODE_POINT);
double H_1 = iHigh(simbol_1,0,iHighest(simbol_1,0,MODE_HIGH,ControlBars,0));
double L_1 = iLow (simbol_1,0,iLowest (simbol_1,0,MODE_LOW, ControlBars,0));
double H_2 = iHigh(simbol_2,0,iHighest(simbol_2,0,MODE_HIGH,ControlBars,0));
double L_2 = iLow (simbol_2,0,iLowest (simbol_2,0,MODE_LOW, ControlBars,0));
double M_1 = (H_1+L_1)/2;
double M_2 = (H_2+L_2)/2;
double Cl_1 = iClose(simbol_1,0,0);
double Cl_2 = iClose(simbol_2,0,0);
double arr_simbol_1 = (Cl_1-M_1)/P_1;
double arr_simbol_2 = (Cl_2-M_2)/P_2;
if(simrev_2)
{
if((arr_simbol_1>0 && arr_simbol_2>0) || (arr_simbol_1<0 && arr_simbol_2<0))
arr_delta = arr_simbol_1+arr_simbol_2;
else arr_delta = 0;
}
else
{
if((arr_simbol_1>0 && arr_simbol_2<0) || (arr_simbol_1<0 && arr_simbol_2>0))
arr_delta = arr_simbol_1-arr_simbol_2;
}
//—-
return(arr_delta);
}
//+——————————————————————+
//| 朽聍弪 蝈牦?腻朦螓, ?镳铟屙蜞? |
//+——————————————————————+
/*double Delta(string simbol_1, string simbol_2, bool simrev_2)
{
//—- 疣聍弪 溧眄
double arr_simbol_2;
double P_1=MarketInfo(simbol_1,MODE_POINT);
double P_2=MarketInfo(simbol_2,MODE_POINT);
double H_1 = iHigh(simbol_1,0,iHighest(simbol_1,0,MODE_HIGH,ControlBars,0));
double L_1 = iLow (simbol_1,0,iLowest (simbol_1,0,MODE_LOW, ControlBars,0));
double H_2 = iHigh(simbol_2,0,iHighest(simbol_2,0,MODE_HIGH,ControlBars,0));
double L_2 = iLow (simbol_2,0,iLowest (simbol_2,0,MODE_LOW, ControlBars,0));
double M_1 = (H_1-L_1)/P_1;
double M_2 = (H_2-L_2)/P_2;
double Cl_1 = iClose(simbol_1,0,0);
double Cl_2 = iClose(simbol_2,0,0);
double arr_modul = (M_1/M_2);
double arr_simbol_1 = (Cl_1-L_1)/P_1/M_1;
if(simrev_2)
arr_simbol_2 = (H_2-Cl_2)/P_2/M_2;
else
arr_simbol_2 = (Cl_2-L_2)/P_2/M_2;
double arr_delta = arr_simbol_1-arr_simbol_2;
//—-
return(arr_delta);
}*/
//+——————————————————————+
//| 泽黻鲨 钺牝 |
//+——————————————————————+
int Object(bool simrev,int a,int b,int o_1)
{
//—-
if(dy==30 && dx==0){dx=150;dy=0;}
if(dy==25 && dx==150){dx=300;dy=0;}
color Color_d;
double D = Delta(Object_y[a], Object_y[b],simrev);
if(D<Delta_level && D>-Delta_level)return(0);
Color_d = DimGray;
if(D>=Delta_level)Color_d = Lime;
if(D<=-Delta_level)Color_d = Red;
string Text_d = StringConcatenate(DoubleToStr(D,0),” “);
Delte[o_1] = StringConcatenate(Sym_sym[a,b],”+”);
ObjectCreate(Delte[o_1], OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(Delte[o_1], OBJPROP_CORNER, 0); // 橡桠珀?筱铍
ObjectSet(Delte[o_1], OBJPROP_XDISTANCE, 850+dx); // 暑铕滂磬蜞 ?
ObjectSet(Delte[o_1], OBJPROP_YDISTANCE, 15+dy*13);// 暑铕滂磬蜞 Y
ObjectSetText(Delte[o_1],Text_d,9,”Arial”,Color_d);// 如戾礤龛?疋铋耱?钺牝?
//—-
if(simrev)Color_d = Red;
else Color_d = Lime;
Text_d = StringConcatenate(Sym_sym[a,b],” “);
DelteText[o_1] = StringConcatenate(Sym_sym[a,b],”++”);
ObjectCreate(DelteText[o_1], OBJ_LABEL, 0, 0, 0);// 杨玟囗桢 钺?
ObjectSet(DelteText[o_1], OBJPROP_CORNER, 0); // 橡桠珀?筱铍
ObjectSet(DelteText[o_1], OBJPROP_XDISTANCE, 720+dx); // 暑铕滂磬蜞 ?
ObjectSet(DelteText[o_1], OBJPROP_YDISTANCE, 15+dy*13);// 暑铕滂磬蜞 Y
ObjectSetText(DelteText[o_1],Text_d,9,”Arial”,Color_d);// 如戾礤龛?疋铋耱?钺牝?
dy++;
//—-
return(0);
}
相关资源
暂无评论...