//// 设置2条线的顺序编号,画法,对应数组,
SetIndexStyle( 0, DRAW_LINE );
SetIndexBuffer( 0, bufferMA1 );
SetIndexStyle( 1, DRAW_LINE );
SetIndexBuffer( 1, bufferMA2 );
return(0);
}
int deinit() { return(0);}
int start()
{
double Buffer10,Buffer11,Buffer20,Buffer21,Buffer30, Buffer31;
int countedBars = IndicatorCounted();
//---- check for possible errors
if ( countedBars < 0 ) { return(-1); }
if ( countedBars > 0 ) { countedBars--; }
int barsToCount = Bars - countedBars;
for ( int i = barsToCount; i >= 0; i-- )
{
//// 开始计算
Buffer20 = iMA(NULL,0,MovingFast,0,MaM,MaP, i) ;//MovingFast
Buffer30 = iMA(NULL,0,MovingSlow,0,MaM,MaP, i) ;//MovingSlow
Buffer21 = iMA(NULL,0,MovingFast,0,MaM,MaP, i+range1) ;
Buffer31 = iMA(NULL,0,MovingSlow02,0,MaM,MaP, i+range2) ;
//赋值给数组以便画线,使用Point使得坐标以点为单位,保证本指标对不同货币的一致y轴单位和视觉效果
bufferMA1[i] = MathRound((Buffer20-Buffer21)/Point);
bufferMA2[i] = MathRound((Buffer30-Buffer31)/Point);
}
return(0);
}
上面把两个MA的差值画在独立窗口,当然若把差值再加上一个MA,就可以画在价格窗口。
MA及其各种变化是最常用的指标基础。MA一般常用来替代价格本身 再做进一步计算。
如改
#property indicator_chart_window
......
Buffer10 = iMA(NULL,0,MovingFast*6,0,MaM,MaP, i)
bufferMA1 = MathRound(Buffer20-Buffer21)+Buffer10 ;
bufferMA2 = MathRound(Buffer30-Buffer31)+Buffer10 ;
.........
就可以把它们跌加到价格上画了。
你只需修改Buffer10 ,Buffer20, Buffer21 Buffer30, Buffer31为你需要的,在考虑一下数据范围坐标问题,你可以画任意的指标了。
使用timeframes参数可获得其它时间周期的数据。
使用Symbol( ) 可获得当前货币对的名称。
使用Point可获得当前货币对的点值。