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

凯尔特纳通道 Keltner Channel.mq4

Keltner Channel 指标创建通道。

图表:Keltner Channel 指标

源码:

//+------------------------------------------------------------------+
//|                                              Keltner Channel.mq4 |
//|                                                  Coded by Gilani |
//|                        Copyright 2005, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright 2005, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red

extern int period = 10;
double upper[], middle[], lower[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
{ 
   SetIndexBuffer(0, upper);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexShift(0, 0);
   SetIndexDrawBegin(0, 0);

   SetIndexBuffer(1, middle);
   SetIndexStyle(1, DRAW_LINE, STYLE_DASHDOT);
   SetIndexShift(1, 0);
   SetIndexDrawBegin(1, 0);

   SetIndexBuffer(2, lower);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexShift(2, 0);
   SetIndexDrawBegin(2, 0);

   SetIndexLabel(0, "KChanUp(" + period + ")");    
   SetIndexLabel(1, "KChanMid(" + period + ")"); 
   SetIndexLabel(2, "KChanLow(" + period + ")"); 
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration 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[])
  {
   int limit;
   double avg;   
   int counted_bars = IndicatorCounted();
   if(counted_bars < 0) 
       return(-1);
   if(counted_bars > 0) 
       counted_bars--;
   limit = Bars - counted_bars;
   for(int x = 0; x < limit; x++) 
     {
      middle[x] = iMA(NULL, 0, period, 0, MODE_SMA, PRICE_TYPICAL, x);
      avg = findAvg(period, x);
      upper[x] = middle[x] + avg;
      lower[x] = middle[x] - avg;
     }
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+  
double findAvg(int period_X, int shift) 
  {
   double sum = 0;
   for(int x = shift; x < (shift + period_X); x++) 
     {     
       sum += High[x] - Low[x];
     }
   sum = sum / period;
   return(sum);
  }  
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 凯尔特纳通道 Keltner Channel.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏