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

另类通道指标 ChandelierStops_v1.mq4

ChandelierStops_v1指标创建另类通道。

图表:ChandelierStops_v1指标

源码:

//+------------------------------------------------------------------+
//|                                           ChandelierStops_v1.mq4 |
//|                                   Copyright @2006, Forex-TSD.com |
//+------------------------------------------------------------------+
#property copyright "Copyright @2006, Forex-TSD.com "
#property link      "http://www.125808047.com/"

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int     Length=15;
extern int     ATRperiod=14;
extern double  Kv=4;
extern int     Shift=1;

double UpBuffer1[];
double DnBuffer1[];
double smin[];
double smax[];
double trend[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   IndicatorBuffers(5);
   SetIndexBuffer(0,UpBuffer1);
   SetIndexBuffer(1,DnBuffer1);
   SetIndexBuffer(2,smin);
   SetIndexBuffer(3,smax);
   SetIndexBuffer(4,trend);

   short_name="ATRStops("+Length+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"Up");
   SetIndexLabel(1,"Dn");

   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| ChandelierStops_v1                                               |
//+------------------------------------------------------------------+
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 shift,limit, counted_bars=IndicatorCounted();

   if(counted_bars > 0) limit=Bars-counted_bars;
   if(counted_bars < 0) return(0);
   if(counted_bars ==0) limit=Bars-Length-1;

   for(shift=limit;shift>=0;shift--)
     {
      smin[shift]=High[Highest(NULL,0,MODE_HIGH,Length,shift+Shift)] - Kv*iATR(NULL,0,ATRperiod,shift+Shift);
      smax[shift]=Low[Lowest(NULL,0,MODE_LOW,Length,shift+Shift)] + Kv*iATR(NULL,0,ATRperiod,shift+Shift);
      trend[shift]=trend[shift+1];

      if(Close[shift] > smax[shift+1])trend[shift]= 1;
      if(Close[shift] < smin[shift+1])trend[shift]=-1;
      if(trend[shift] >0)
        {
         if(smin[shift]<smin[shift+1])smin[shift]=smin[shift+1];
         UpBuffer1[shift]=smin[shift];
         DnBuffer1[shift]=EMPTY_VALUE;
        }
      if(trend[shift] <0)
        {
         if(smax[shift]>smax[shift+1])smax[shift]=smax[shift+1];
         UpBuffer1[shift]=EMPTY_VALUE;
         DnBuffer1[shift]=smax[shift];
        }
     }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 另类通道指标 ChandelierStops_v1.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏