Разве корридор значений корреляции не от 0 до 1 ??????
Разве корридор значений корреляции не от 0 до 1 ??????
Не от 0 до 1, а от -1 до +1,но не у всех пар корреляция гуляет в таком диапозоне..Да и значения у самых сильноскоррелированных пар до еденицы не доходят...0.96-0.98.
Спасибо за индюк, немного поправил его
else{ z=iBarShift(OtherChart,0,iTime(Symbol(),0,i+k),false); y=(iOpen(OtherChart,0,z)*UseOpen+iClose(OtherChart,0,z)*UseClose+iHigh(OtherChart,0,z)*UseHigh+iLow(OtherChart,0,z)*UseLow)/(UseOpen+UseClose+UseHigh+UseLow); }
Что отслеживает соответствие баров не по номеру, а по времени
Ну и цветовую раскраску добавил
//+------------------------------------------------------------------+ //| Correlation.mq4 | //| Безбородов Алексей | //| AlexeiBv@ya.ru | //+------------------------------------------------------------------+ #property copyright "Безбородов Алексей" #property link "AlexeiBv@ya.ru" //---- #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Black #property indicator_color2 Green #property indicator_color3 Red //---- extern string OtherChart="EURUSD"; extern int n=20; extern bool UseOpen=true; extern bool UseClose=false; extern bool UseHigh=false; extern bool UseLow=false; extern int CalcBars=400; //---- double ExtBuffer0[]; double ExtBuffer1[]; double ExtBuffer2[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators string short_name; //---- 1 additional buffer used for counting. IndicatorBuffers(3); IndicatorDigits(Digits+1); //---- indicator line SetIndexStyle(0,DRAW_NONE); SetIndexStyle(1,DRAW_HISTOGRAM); SetIndexStyle(2,DRAW_HISTOGRAM); SetIndexBuffer(0,ExtBuffer0); SetIndexBuffer(1,ExtBuffer1); SetIndexBuffer(2,ExtBuffer2); // SetIndexBuffer(1,TempBuffer); //---- name for DataWindow and indicator subwindow label short_name="Correlation("+n+")"; IndicatorShortName(short_name); SetIndexLabel(0,short_name); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { // Print("True "+true+" false "+false ); int i,k,counted_bars=IndicatorCounted(); double sx,sy,x,y,cor1,cor2,cor3, z; double prev,current; //---- if(Bars<=n) return(0); //---- int limit=Bars-counted_bars; if(counted_bars>0) limit++; for(i=0; i<CalcBars; i++) { sx=0; sy=0; for(k=0; k<n; k++) { if((UseOpen+UseClose+UseHigh+UseLow)==0) x=0; else x=(Open[i+k]*UseOpen+Close[i+k]*UseClose+High[i+k]*UseHigh+Low[i+k]*UseLow)/(UseOpen+UseClose+UseHigh+UseLow); if((UseOpen+UseClose+UseHigh+UseLow)==0) y=0; else{ z=iBarShift(OtherChart,0,iTime(Symbol(),0,i+k),false); y=(iOpen(OtherChart,0,z)*UseOpen+iClose(OtherChart,0,z)*UseClose+iHigh(OtherChart,0,z)*UseHigh+iLow(OtherChart,0,z)*UseLow)/(UseOpen+UseClose+UseHigh+UseLow); } sx+=x;sy+=y; } sx/=n;sy/=n; cor1=0;cor2=0;cor3=0; for(k=0; k<n; k++) { if((UseOpen+UseClose+UseHigh+UseLow)==0) x=0; else x=(Open[i+k]*UseOpen+Close[i+k]*UseClose+High[i+k]*UseHigh+Low[i+k]*UseLow)/(UseOpen+UseClose+UseHigh+UseLow); if((UseOpen+UseClose+UseHigh+UseLow)==0) y=0; else{ z=iBarShift(OtherChart,0,iTime(Symbol(),0,i+k),false); y=(iOpen(OtherChart,0,z)*UseOpen+iClose(OtherChart,0,z)*UseClose+iHigh(OtherChart,0,z)*UseHigh+iLow(OtherChart,0,z)*UseLow)/(UseOpen+UseClose+UseHigh+UseLow); } cor1+=(x-sx)*(y-sy); cor2+=(x-sx)*(x-sx); cor3+=(y-sy)*(y-sy); } ExtBuffer0[i]=cor1/MathSqrt(cor2)/MathSqrt(cor3); } bool up=true; for(i=limit-1; i>=0; i--) { current=ExtBuffer0[i]; prev=ExtBuffer0[i+1]; if(current>prev) up=true; if(current<prev) up=false; if(!up) { ExtBuffer2[i]=current; ExtBuffer1[i]=0.0; } else { ExtBuffer1[i]=current; ExtBuffer2[i]=0.0; } } //---- return(0); } //+------------------------------------------------------------------+
Оч интересно выглядят корреляции Евро-Золото, Индексы акций-Облигации
Зависимость с фунтфранком (при другой Евродоллар) есть немного - даже иногда с опережением, остальные основные пары - непонятно как воспользоваться зависимостями. Смотрел М30. Большие периоды неинтересны. Чисто ИМХО. Автору скажу, что такой труд даром не пропадет. Идею есть смысл развивать.
It is a follow up to the modification suggested by MQL4 Comments:
else{ z=iBarShift(OtherChart,0,iTime(Symbol(),0,i+k),false);
I suggest to replace the Symbol() with OtherChart as below.
Th reason while the previous modification works for some charts like EURUSD.
It does not work well for DXY_U7. I do not know the exact reason. But changing the parameter gives the correct correlation values.
The iBarShift looks up the iTime index value on the OtherChart for the corresponding time value.
else{ z=iBarShift(OtherChart,0,iTime(OtherChart(),0,i+k),false);
It is a follow up to the modification suggested by MQL4 Comments:
I suggest to replace the Symbol() with OtherChart() as below.
The reason is while the previous modification works for some charts like EURUSD.
It does not work well for DXY_U7. I do not know the exact reason. But changing the parameter gives the correct correlation values.
The iBarShift looks up the iTime index value on the OtherChart for the corresponding time value.
Thank you Alexei.
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Вы принимаете политику сайта и условия использования
Correlation:
Author: John Smith