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

均线通道类指标 HMAenv

HMAenv指标创建另类均线通道。

HMAenv指标图表:HMAenv指标

HMAenv指标源码:

//+------------------------------------------------------------------+
//|                                                       HMAenv.mq4 |
//|                                  Nick Bilak, beluck[AT]gmail.com |
//+------------------------------------------------------------------+
#property copyright "Copyright @2006, Nick Bilak"
#property link      "http://www.125808047.com"

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

input int _maPeriod=20;
input double deviation = 0.1;
input int price1 = PRICE_OPEN;
int price1shift = 0;
int price2shift = 0;
extern int price2 = PRICE_OPEN;
/*
PRICE_CLOSE 0 Close price. 
PRICE_OPEN 1 Open price. 
PRICE_HIGH 2 High price. 
PRICE_LOW 3 Low price. 
PRICE_MEDIAN 4 Median price, (high+low)/2. 
PRICE_TYPICAL 5 Typical price, (high+low+close)/3. 
PRICE_WEIGHTED 6 Weighted close price, (high+low+close+close)/4. 
*/

double _hma[],_wma[],hma[],wma[],b1[],b2[];
int ExtCountedBars=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit(void)
  {
   if (price1!=PRICE_OPEN) price1shift = 1;
   if (price2!=PRICE_OPEN) price2shift = 1;
	IndicatorBuffers(6);
	SetIndexBuffer(0, b1);
	SetIndexStyle(0, DRAW_LINE);
	SetIndexEmptyValue(0, 0.0);
	SetIndexBuffer(1, b2);
	SetIndexStyle(1, DRAW_LINE);
	SetIndexEmptyValue(1, 0.0);
	SetIndexBuffer(2, _hma);
	SetIndexEmptyValue(2, 0.0);
	SetIndexBuffer(3, _wma);
	SetIndexEmptyValue(3, 0.0);
	SetIndexBuffer(4, hma);
	SetIndexEmptyValue(4, 0.0);
	SetIndexBuffer(5, wma);
	SetIndexEmptyValue(5, 0.0);
	IndicatorDigits(Digits);
  Comment("www.125808047.com");
}

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;
	int maxBars=_maPeriod*2;
	int period=_maPeriod;
	double sqrtPeriod = sqrt(period*1.00);
	int halfPeriod=period/2;

	if(rates_total<_maPeriod) return(-1);
	int limit=rates_total-prev_calculated+maxBars;

	double wma1,_wma1;
	double wma2,_wma2;
	for(i=limit; i>=0; i--) {
	  _wma1 = iMA(Symbol(), 0, period, 0, MODE_LWMA, price1, i+price1shift);
	  _wma2 = iMA(Symbol(), 0, halfPeriod, 0, MODE_LWMA, price1, i+price1shift);
	  _wma[i] = 2.0*_wma2-_wma1;
	  wma1 = iMA(Symbol(), 0, period, 0, MODE_LWMA, price2, i+price2shift);
	  wma2 = iMA(Symbol(), 0, halfPeriod, 0, MODE_LWMA, price2, i+price2shift);
	  wma[i] = 2.0*wma2-wma1;
	} 
	
	for(i=limit; i>=0; i--) {
	  _hma[i]=iMAOnArray(_wma, 0, sqrtPeriod, 0, MODE_LWMA, i);
	  hma[i]=iMAOnArray(wma, 0, sqrtPeriod, 0, MODE_LWMA, i);
	  b1[i]=_hma[i]+_hma[i]*deviation/100.0;
	  b2[i]=hma[i]-hma[i]*deviation/100.0;
	} 
return(rates_total);
}
打赏
版权所有转载请注明标题及链接:峰汇在线 » 均线通道类指标 HMAenv
上一篇:
下一篇:
分享到: 更多 (0)

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

支付宝扫一扫打赏

微信扫一扫打赏