有您的持续关注
我们会做得更好

MT4自定义指标 布林带



布林带指标MQL4源码如下:

//+------------------------------------------------------------------+
//|                                                       布林带.mq4 |
//|                                                www.125808047.com |
//+------------------------------------------------------------------+
#property copyright "www.125808047.com"
#property link      "http://www.125808047.com"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Magenta
#property indicator_color2 Blue
#property indicator_color3 Blue

extern int BandsPeriod = 20;
extern int BandsShift = 0;
extern double BandsDeviations = 2.0;
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];

int init() {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, g_ibuf_92);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, g_ibuf_96);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexBuffer(2, g_ibuf_100);
   SetIndexDrawBegin(0, BandsPeriod + BandsShift);
   SetIndexDrawBegin(1, BandsPeriod + BandsShift);
   SetIndexDrawBegin(2, BandsPeriod + BandsShift);
   return (0);
}

int start() {
   int li_4;
   double ld_12;
   double ld_20;
   double ld_28;
   double ld_36;
   int l_ind_counted_8 = IndicatorCounted();
   if (Bars <= BandsPeriod) return (0);
   if (l_ind_counted_8 < 1) {
      for (int li_0 = 1; li_0 <= BandsPeriod; li_0++) {
         g_ibuf_92[Bars - li_0] = EMPTY_VALUE;
         g_ibuf_96[Bars - li_0] = EMPTY_VALUE;
         g_ibuf_100[Bars - li_0] = EMPTY_VALUE;
      }
   }
   int li_44 = Bars - l_ind_counted_8;
   if (l_ind_counted_8 > 0) li_44++;
   for (li_0 = 0; li_0 < li_44; li_0++) g_ibuf_92[li_0] = iMA(NULL, 0, BandsPeriod, BandsShift, MODE_SMA, PRICE_CLOSE, li_0);
   li_0 = Bars - BandsPeriod + 1;
   if (l_ind_counted_8 > BandsPeriod - 1) li_0 = Bars - l_ind_counted_8 - 1;
   while (li_0 >= 0) {
      ld_20 = 0.0;
      li_4 = li_0 + BandsPeriod - 1;
      ld_28 = g_ibuf_92[li_0];
      while (li_4 >= li_0) {
         ld_36 = Close[li_4] - ld_28;
         ld_20 += ld_36 * ld_36;
         li_4--;
      }
      ld_12 = BandsDeviations * MathSqrt(ld_20 / BandsPeriod);
      g_ibuf_96[li_0] = ld_28 + ld_12;
      g_ibuf_100[li_0] = ld_28 - ld_12;
      li_0--;
   }
   return (0);
}

如您喜欢此文章请点下面分享按钮↴峰汇在线 » MT4自定义指标 布林带
上一篇:
下一篇:
分享到:更多 ()