#property copyright "kitgain 2015.12.25 Q7318875"
#property link "http://qun.yunpan.360.cn/1265799"
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Yellow
#property indicator_width1 2
#property indicator_color2 RoyalBlue
#property indicator_width2 2
#property indicator_color3 Red
#property indicator_width3 2
//---- input parameters
extern int Price = 0; //Apply to Price(0-Close;1-Open;2-High;3-Low;4-Median price;5-Typical price;6-Weighted Close)
extern int Length = 10;//Period of NonLagMA
extern int Displace = 0; //DispLace or Shift
extern int Filter = 0; //Dynamic filter in decimal
extern int Color = 1; //选0,第一种颜色,选1,有颜色
extern int ColorBarBack = 2; //Bar back for color mode 回退变色
extern double Deviation = 0; //Up/down deviation
double Cycle = 4;
//---- indicator buffers
double MABuffer[];
double UpBuffer[];
double DnBuffer[];
double price[];
double trend[];
int init()
{
//int ft=0;
string short_name;
//---- indicator line
IndicatorBuffers(5);
SetIndexStyle(0,DRAW_ARROW);
SetIndexBuffer(0,MABuffer);
SetIndexStyle(1,DRAW_ARROW);
SetIndexBuffer(1,UpBuffer);
SetIndexStyle(2,DRAW_ARROW);
SetIndexBuffer(2,DnBuffer);
SetIndexBuffer(3,price);
SetIndexBuffer(4,trend);
IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS));
SetIndexArrow(0,159);
SetIndexArrow(1,159);
SetIndexArrow(2,159);
SetIndexArrow(3,159);//点
//---- name for DataWindow and indicator subwindow label
short_name="NonLagDot("+Length+")";
IndicatorShortName(short_name);
SetIndexLabel(0,"NLD");
SetIndexLabel(1,"Up");
SetIndexLabel(2,"Dn");
//----
SetIndexShift(0,Displace);
SetIndexShift(1,Displace);
SetIndexShift(2,Displace);
SetIndexDrawBegin(0,Length*Cycle+Length);
SetIndexDrawBegin(1,Length*Cycle+Length);
SetIndexDrawBegin(2,Length*Cycle+Length); //10*4+10
//----
return(0);
}
//+------------------------------------------------------------------+
//| NonLagMA_v4 |
//+------------------------------------------------------------------+
int start()
{
int i,shift, counted_bars=IndicatorCounted(),limit;
double alfa, beta, t, Sum, Weight, g;
double pi = 3.1415926535;
double Coeff = 3*pi; //1.5Hz
int Phase = Length-1; //10-1=9
double Len = Length*Cycle + Phase; //10*4+9
if ( counted_bars > 0 ) limit=Bars-counted_bars;
if ( counted_bars < 0 ) return(0);
if ( counted_bars ==0 ) limit=Bars-Len-1; //Bars-49-1
if ( counted_bars < 1 )
for(i=1;i<Length*Cycle+Length;i++) //i<50
{
MABuffer[Bars-i]=0;
UpBuffer[Bars-i]=0;
DnBuffer[Bars-i]=0;
}
for(shift=limit;shift>=0;shift--)
{
Weight=0; Sum=0; t=0;
for (i=0;i<=Len-1;i++) //Len=49
{
g = 1.0/(Coeff*t+1); // 1/(3π*t+1)
if (t <= 0.5 ) g = 1; // 最近4柱g=1
beta = MathCos(pi*t);
alfa = g * beta; // 正常波动函数cos(πt)/(3πt+1)
//if (shift>=1) price[i] = iMA(NULL,0,Per,Displace,Mode,Price,shift+i);
//else
price[i] = iMA(NULL,0,1,0,MODE_SMA,Price,shift+i); //收盘价Price=0,即PRICE_CLOSE
Sum += alfa*price[i]; //量和
Weight += alfa; //权重和
if(t<1) t += 1.0/(Phase-1); //递加0.125 8Hz
else if(t<Len-1) t += (2*Cycle-1)/(Cycle*Length-1);//t<48的情况下,t递加7/39=0.179 5.57Hz
}
if (Weight > 0) MABuffer[shift] = (1.0+Deviation/100)*Sum/Weight; //0
if (Filter>0)
{
if( MathAbs(MABuffer[shift]-MABuffer[shift+1]) < Filter*Point ) MABuffer[shift]=MABuffer[shift+1];
}
if (Color>0)
{
trend[shift]=trend[shift+1];
if (MABuffer[shift]-MABuffer[shift+1] > Filter*Point) trend[shift]= 1;
if (MABuffer[shift+1]-MABuffer[shift] > Filter*Point) trend[shift]=-1;
if (trend[shift]>0)
{
UpBuffer[shift] = MABuffer[shift];
if (trend[shift+ColorBarBack]<0) UpBuffer[shift+ColorBarBack]=MABuffer[shift+ColorBarBack];
DnBuffer[shift] = EMPTY_VALUE;
}
if (trend[shift]<0)
{
DnBuffer[shift] = MABuffer[shift];
if (trend[shift+ColorBarBack]>0) DnBuffer[shift+ColorBarBack]=MABuffer[shift+ColorBarBack];
UpBuffer[shift] = EMPTY_VALUE;
}
}
}
return(0);
}
这个指标用于交叉盘最佳,H4以上最佳。
ColorBarBack用于回退变色(有点像重绘),可设置为0,不变色;
Length代表周期,默认10柱。
在前5柱,权重g一直为1;
t在1.0之前按1/8递增,其后按7/39递增;
beta使用余弦函数;
最终alfa表示使用了余弦函数在第一象限的快速下跌图象,到第5柱之后,使用衰减震荡平面波动函数cos(πt)/(3πt+1)...
部分计算结果如下:
综合函数图象如下,
上图显示,原作者构造的函数,现柱权限为1.0,前五柱按余弦函数第一象限快速下跌,随后惯性下跌为负相关到倒数第7柱(不含现柱),之后是震荡衰减模式,整体上基本合理。


发表评论