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

通道指标 Chande_Kroll_Stop_v1.mq4

Chande_Kroll_Stop_v1指标创建价格通道。

图表:Chande_Kroll_Stop_v1指标

源码:

//+------------------------------------------------------------------+
//|                                         Chande_Kroll_Stop_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    =20;
extern int    ATRPeriod =10;
extern double Kv        =3;

double UpTrend[];
double DnTrend[];
double smin[];
double smax[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;

   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   IndicatorBuffers(4);
   SetIndexBuffer(0,UpTrend);
   SetIndexBuffer(1,DnTrend);
   SetIndexBuffer(2,smin);
   SetIndexBuffer(3,smax);

   short_name="Chande Kroll Stop("+Length+","+ATRPeriod+","+Kv+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,"UpTrend");
   SetIndexLabel(1,"DnTrend");

   SetIndexDrawBegin(0,Length);
   SetIndexDrawBegin(1,Length);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Chande_Kroll_Stop_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,ATRPeriod,shift)] - Kv*iATR(NULL,0,ATRPeriod,shift);
      smax[shift]=Low [Lowest (NULL,0,MODE_LOW ,ATRPeriod,shift)] + Kv*iATR(NULL,0,ATRPeriod,shift);

      UpTrend[shift]=-10000000;
      DnTrend[shift]= 10000000;

      for(int i=Length-1;i>=0;i--)
        {
         UpTrend[shift]=MathMax( UpTrend[shift], smin[shift+i]);
         DnTrend[shift]=MathMin( DnTrend[shift], smax[shift+i]);
        }
     }
   return(rates_total);
  }
打赏
版权所有转载请注明标题及链接:峰汇在线 » 通道指标 Chande_Kroll_Stop_v1.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏