在论坛里下了很多EA学到了不少东西,所以公布一下私人用的指标源码,回馈大家!
指标是根据考夫曼的自适应均线稍微修改了一下,提升了对盘整和趋势的判断
在盘整的时候完全一条直线,在趋势的时候是陡峭的斜线。
201832xgkotbbzzccnxtxf.jpg
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Aqua
#property indicator_width1 2
extern int PriceMode=0;//0-MID;1-HIGH;2-LOW;3-CLOSE;
extern int NoisePeriod=5;//越短对变化越敏感,越长,对短期上下急速波动的反应也越弱
extern int a=8;
extern double c=0.4;//调节噪声率的数值,数值越大对变化越迟钝,越小,对变化越敏感;
extern double Pow=2;//越大,平滑系数的脱敏度也越大
extern double DigitsAdjuster=10;//过滤小的变动
extern double Fastest=2;//最短周期
extern double Slowest=89;//最长周期
double AMA_Buffer[];
int init()
{
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,AMA_Buffer);
SetIndexDrawBegin(0,NoisePeriod);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
return(0);
}
int deinit()
{
return(0);
}
int start()
{
int CountedBars=IndicatorCounted();
int i,Position=Bars-CountedBars;
double AppliedPrice=0;
double AMA_0=0;
string Price="";
if (CountedBars>0)//重算倒数第二根K线
{
CountedBars--;
}
if (CountedBars==0)
{
i=Position-NoisePeriod;
}
else
{
i=Position;
}
while (i>=0)
{
if (PriceMode==0)
{
AppliedPrice=(High+Low)/2;
Price="MID";
}
if (PriceMode==1)
{
AppliedPrice=High;
Price="H";
}
if (PriceMode==2)
{
AppliedPrice=Low;
Price="L";
}
if (PriceMode==3)
{
AppliedPrice=Close;
Price="C";
}
if (i==Position-NoisePeriod)
{
AMA_Buffer=AppliedPrice;
}
else
{
AMA_0=AMA_Buffer[i+1]+Calculater(i)*(AppliedPrice-AMA_Buffer[i+1]);
AMA_0=MathRound(AMA_0/(DigitsAdjuster*Point))*DigitsAdjuster*Point;
AMA_Buffer=AMA_0;
}
i--;
}
return(0);
}
double Calculater(int Position)
{
double Fast=2/(Fastest+1);
double Slow=2/(Slowest+1);
double Smooth=NoiseRate(Position)*(Fast-Slow)+Slow;
double C=MathPow(Smooth,Pow);
return(C);
}
double NoiseRate(int Position)
{
double H_Shift=iHighest(Symbol(),0,PRICE_HIGH,NoisePeriod,Position);
double H_Price=iHigh(Symbol(),0,H_Shift);
double L_Shift=iLowest(Symbol(),0,PRICE_LOW,NoisePeriod,Position);
double L_Price=iLow(Symbol(),0,L_Shift);
double Noise=NoiseAccumulator(Position);
double NoiseRate=(H_Price-L_Price)/Noise;
NoiseRate=a*NoiseRate-(a-1)*c;
if (NoiseRate>1)
{
NoiseRate=1;
}
if (NoiseRate<0)
{
NoiseRate=0;
}
return(NoiseRate);
}
double NoiseAccumulator(int Position)
{
double NoiseTotal=0.0000000001;
double TR1,TR2,TR3,TR4;
for (int i=Position;i<Position+NoisePeriod;i++)
{
TR1=High-Low;
TR2=MathAbs(Low-Low[i+1]);
TR3=MathAbs(High-High[i+1]);
TR4=MathMax(TR2,TR3);
NoiseTotal+=MathMax(TR1,TR4);
}
return(NoiseTotal);
}
|