变色均线功能:显示均线上涨为红色,下跌为绿色。多周期看趋势更加明显些。
显示如下图:
文华变色均线代码如下:
MA60:MA(CLOSE,60);
M60:=MA(CLOSE,60);
DRAWCOLORLINE(REF(M60,1) > REF(M60,2), M60,COLORRED,COLORGREEN);
tbquant变色均线源码:
Params
Numeric Length1(60);
Numeric Length2(60);
Numeric Length3(60);
Vars
Series<Numeric> MAValue1;
Series<Numeric> MAValue2;
Series<Numeric> MAValue3;
Events
OnBar(ArrayRef<Integer> indexs)
{
Range[0:DataSourceSize() - 1]
{
If(Length1 > 0)
{
MAValue1 = AverageFC(Close,Length1);
if (MAValue1[1] >= MAValue1[2])
//PlotAuto("OpenToClose",open,close,Blue,Enum_Line,Enum_Solid,Enum_2Pix);
PlotAuto("ma1",MAValue1,0,Red,Enum_Line,Enum_Solid,Enum_1Pix);
Else
PlotAuto("ma1",MAValue1,0,Green,Enum_Line,Enum_Solid,Enum_1Pix);
}
If(Length2 > 0)
{
MAValue2 = AverageFC(Close,Length2);
if (MAValue2[1] >= MAValue2[2])
PlotAuto("ma2",MAValue2,0,Red,Enum_Line,Enum_Solid,Enum_3Pix);
Else
PlotAuto("ma2",MAValue2,0,Green,Enum_Line,Enum_Solid,Enum_3Pix);
}
If(Length3 > 0)
{
MAValue3 = AverageFC(Close,Length3);
if (MAValue3[1] >= MAValue3[2])
PlotAuto("ma3",MAValue3,0,Red, Enum_Line,Enum_Solid,Enum_6Pix);
Else
PlotAuto("ma3",MAValue3,0,Green,Enum_Line,Enum_Solid,Enum_6Pix);
}
}
}
显示效果如下: