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

ATR指标 Hull_Style_ATR

Hull_Style_ATR指标创建另类ATR。

Hull_Style_ATR指标图表:Hull_Style_ATR指标

Hull_Style_ATR指标源码:

//+------------------------------------------------------------------+
//|                                               Hull_Style_ATR.mq4 |
//+------------------------------------------------------------------+
#property  copyright ""
#property  link      "http://www.125808047.com/"

#property  indicator_separate_window
#property  indicator_buffers 2
#property  indicator_color1  LightSeaGreen
#property  indicator_color2  Purple

input int Atr_Time            =  0;
input int ATR_Period          = 14;
input int SignalLine_Period   = 21;
input int SignalLineShift     =  3;
input int SignalLineMa_Method =  0; // 0 SMA , 1 EMA , 2 SMMA , 3 LWMA

double preatrbuffer[];
double finalatrbuffer[];
int    draw_begin0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
 {
  draw_begin0 = ATR_Period+MathFloor(MathSqrt(ATR_Period));
  
  SetIndexEmptyValue(0,0.0000);
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(0,preatrbuffer);
  SetIndexLabel(0,"ATR");
  SetIndexDrawBegin(0,draw_begin0);
  
  SetIndexEmptyValue(1,0.0000);
  SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,1);
  SetIndexBuffer(1,finalatrbuffer);
  SetIndexLabel(1,"ATR");
  SetIndexDrawBegin(1,draw_begin0);

  IndicatorShortName("Hull_Style_ATR("+IntegerToString(ATR_Period)+")");
  Comment("www.125808047.com");
  return(0);
 }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 i,limit;
   if(rates_total<=ATR_Period)
      return(0);

   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
  
  for(i=0; i<limit; i++)
    { preatrbuffer[i] = (iATR(Symbol(), Atr_Time, MathFloor(ATR_Period/2), i)*2) - iATR(Symbol(), Atr_Time, ATR_Period, i); }
  
  for(i=0; i<limit; i++)
    { finalatrbuffer[i]=iMAOnArray(preatrbuffer,0,MathFloor(MathSqrt(SignalLine_Period)),SignalLineShift,SignalLineMa_Method,i); }
  return(rates_total);
 }
打赏
版权所有转载请注明标题及链接:峰汇在线 » ATR指标 Hull_Style_ATR
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏