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

通道指标 Donchian Channels – Generalized version1.mq4

Donchian Channels – Generalized version1指标创建价格通道。

图表:Donchian Channels - Generalized version1指标

源码:

//+------------------------------------------------------------------+
//|                     Donchian Channels - Generalized version1.mq4 |
//|                          Copyright @2005, Luis Guilherme Damiani |
//+------------------------------------------------------------------+
#property copyright "Copyright @2005, Luis Guilherme Damiani"
#property link      "http://www.125808047.com/"
//----
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Magenta
#property indicator_color2 SteelBlue

extern int       Periods=24;
extern int       Extremes=3;
extern int       Margins=-2;
extern int       Advance=0;
extern int       max_bars=700;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   SetIndexStyle(0,DRAW_LINE,1,2);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE,1,2);
   SetIndexBuffer(1,ExtMapBuffer2);
   IndicatorShortName("DoC("+Periods+")");
   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    fixed_bars=IndicatorCounted();

   double smin=0, smax=0, SsMax=0, SsMin=0;

   if(max_bars==0) max_bars=Bars;

   for(int shift=0;shift< max_bars;shift++)
     {
      if (Extremes ==1)
        {
         SsMax=High[Highest(NULL,0,MODE_HIGH,Periods,shift)];
         SsMin=Low[Lowest(NULL,0,MODE_LOW,Periods,shift)];
        }
      else if (Extremes==3)
           {
            SsMax=(Open[Highest(NULL,0,MODE_OPEN,Periods,shift)]+High[Highest(NULL,0,MODE_HIGH,Periods,shift)])/2;
            SsMin=(Open[Lowest(NULL,0,MODE_OPEN,Periods,shift)]+Low[Lowest(NULL,0,MODE_LOW,Periods,shift)])/2;
           }
         else
           {
            SsMax=Open[Highest(NULL,0,MODE_OPEN,Periods,shift)];
            SsMin=Open[Lowest(NULL,0,MODE_OPEN,Periods,shift)];
           }
      smin=SsMin+(SsMax-SsMin)*Margins/100;
      smax=SsMax-(SsMax-SsMin)*Margins/100;
      ExtMapBuffer1[shift-Advance]=smin;
      ExtMapBuffer2[shift-Advance]=smax;
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 通道指标 Donchian Channels – Generalized version1.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏