诚信为本
量力而为
当前位置:首页MetaTrader 4MT4指标热力函数 EntropyMath.mq4

热力函数 EntropyMath.mq4

EntropyMath 指标副图创建曲线,计算方法是选择随机的样本。

图表:EntropyMath 指标

源码:

//+------------------------------------------------------------------+
//|                                                  EntropyMath.mq4 |
//|                                                    Aleksandr Pak |
//+------------------------------------------------------------------+
#property  copyright "Copyright @2008, MetaQuotes Software Corp."
#property link      "http://www.125808047.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Lime
#property indicator_level1 0.0001
#property indicator_level2 -0.0001

double entropy[];
extern int numbars=14;
//+------------------------------------------------------------------+
int OnInit(void)
{
	SetIndexBuffer(0,entropy); SetIndexStyle(0,DRAW_LINE); IndicatorShortName("Entropy("+numbars+")");
	IndicatorDigits(3*Digits);
   Comment("www.125808047.com");
   return(INIT_SUCCEEDED);
}

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[])
  {
	double  P, G;
	int in, out;
	int i,j;
	double sumx = 0.0;
	double sumx2 = 0.0;
	double avgx = 0.0;
	double rmsx = 0.0;
	
	in=0;  
	out=0; 
	int count = IndicatorCounted();

	for (i=0; i<Bars-count+1; i++)
	{
		if (i>Bars-numbars+1) entropy[out] = EMPTY_VALUE;
		else 
		{
			sumx = 0; sumx2=0 ; avgx =0; rmsx = 0.0;
			for (j=0;j<numbars+1;j++)
			{
				double r=MathLog(Close[in+j] / Close[in+j+1]) ;
				sumx += r;
				sumx2 += r * r;
			}
		if (numbars==0)  { avgx = Close[in]; rmsx = 0.0; }
		else  { avgx = sumx / numbars; rmsx = MathSqrt(sumx2/numbars); }
		P = ((avgx/rmsx)+1)/2.0;
		G = P * MathLog(1+rmsx) + (1-P) * MathLog(1-rmsx);
		entropy[out]=G;
	}
	in++; out++;
	}
return(rates_total);
}
版权所有转载请注明标题及链接:峰汇在线 » 热力函数 EntropyMath.mq4
上一篇:
下一篇:
分享到: 更多 (0)