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

高低点价差线指标 CHV.mq4

CHV指标计算价格高低点的差值并在副图创建价差线。

图表:

CHV指标

源码:

//+------------------------------------------------------------------+
//|                                                          CHV.mq4 |
//|                      Copyright @2007, MetaQuotes Software Corp. |
//+------------------------------------------------------------------+
#property copyright "Copyright @2007, MetaQuotes Software Corp."
#property link      "http://www.125808047.com/"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DarkBlue

extern int       SmoothPeriod=10;
extern int       ROCPeriod=10;
extern int       TypeSmooth=1;

double CHV[];
double HL[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
{
   string name,smoothString;
   if (TypeSmooth<0 || TypeSmooth>1) TypeSmooth=1;
   if (TypeSmooth==0) smoothString="SMA"; else smoothString="EMA";
   name="Chaikin Volatility("+SmoothPeriod+","+smoothString+")";

   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHV);
   SetIndexLabel(0,name);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1,HL);
   SetIndexEmptyValue(1,0.0);
   IndicatorShortName(name);
   IndicatorDigits(1);
   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    counted_bars=IndicatorCounted();
   int limit,i;
   double curr_value,shift_value;

   if (counted_bars<0) return(-1);

   if (counted_bars==0) 
      {
      limit=Bars-1;
      for (i=limit;i>=0;i--)
        {
         HL[i]=High[i]-Low[i];
        }
      for(i=limit-2*SmoothPeriod;i>=0;i--)
        {
         curr_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i);
         shift_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i+ROCPeriod);
         CHV[i]=(curr_value-shift_value)/shift_value*100;
        }
      }

   if (counted_bars>0) 
     {
      limit=Bars-counted_bars;
      for (i=limit;i>=0;i--)
        {
         HL[i]=High[i]-Low[i];
        }
      for(i=limit;i>=0;i--)
        {
         curr_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i);
         shift_value=iMAOnArray(HL,0,SmoothPeriod,0,TypeSmooth,i+ROCPeriod);
         CHV[i]=(curr_value-shift_value)/shift_value*100;
        }
      }            
   return(rates_total);
  }
//+------------------------------------------------------------------+
打赏
版权所有转载请注明标题及链接:峰汇在线 » 高低点价差线指标 CHV.mq4
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏