诚信为本
量力而为
当前位置:峰汇在线 > MetaTrader 4 > MT4指标 > 正文

Corr.mq4

Corr指标显示价格收盘和开盘的变化。

图表:Corr指标

源码:

//+------------------------------------------------------------------+
//|                                                         Corr.mq4 |
//|                                                             Nike |
//+------------------------------------------------------------------+
#property copyright "Nike"
#property link      "http://www.125808047.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red

extern int CorrLen = 7;

double ExtMapBuffer[];
double Buffer1[];
double Buffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   IndicatorBuffers(3);
   SetIndexStyle(0, DRAW_LINE, EMPTY, 2);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexBuffer(1, Buffer1);
   SetIndexBuffer(2, Buffer2);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator start function                                  |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   for(int i = 0; i < Bars; i++)
       ExtMapBuffer[i] = Close[i] - Open[i];  

   for(i = 0; i < Bars - CorrLen; i++)
       ExtMapBuffer[i] = corr(ExtMapBuffer, i, CorrLen);
   return(rates_total);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double corr(double& a[], int start, int len)
  {
   double m1 = 0; 
   double m2 = 0; 
   double m1_2 = 0; 
   double m2_2 = 0; 
   double m12 = 0;

   for(int i = 0; i < len; i++)
     {
       m1 = m1 + a[i];
       m2 = m2 + a[start + i];
       m1_2 = m1_2 + a[i]*a[i];
       m2_2 = m2_2 + a[start + i]*a[start + i];
       m12 = m12 + a[i]*a[start + i];
     }
   m1 = m1/len;
   m2 = m2/len;
   m1_2 = m1_2/len;
   m2_2 = m2_2/len;
   m12 = m12/len;
   if((m1_2 - m1*m1)*(m2_2 - m2*m2) == 0) 
       return(0);
   return((m12 - m1*m2) / MathSqrt(MathAbs((m1_2 - m1*m1)*(m2_2 - m2*m2))));
}
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » Corr.mq4
上一篇:
下一篇:
分享到: 更多 (0)

如您觉得此文不错请扫码打赏!

支付宝扫一扫打赏

微信扫一扫打赏