Код: Выделить всё
function Initialize()
{
IndicatorName = "MACD_chart";
PriceStudy = true;
AddInput("Input", Inputs.Price);
AddParameter("PFast", 10);
AddParameter("PSlow", 20, 2);
AddParameter("PSig", 10);
AddSeries("S", DrawAs.Custom, Color.Red);
AddSeries("B", DrawAs.Custom, Color.Blue);
AddSeries("Line", DrawAs.Line, Color.Gray,false);
AddSeries("Signal", DrawAs.Line, Color.Red,false);
AddLevel(0, Color.Gray, "Line");
AddGlobalVariable("EMA1", Types.Double, 0.0);
AddGlobalVariable("EMA2", Types.Double, 0.0);
AddGlobalVariable("KC1", Types.Double, 0.0);
AddGlobalVariable("KC2", Types.Double, 0.0);
AddGlobalVariable("KC", Types.Double, 0.0);
}
function Evaluate()
{
S=Input.Close;
B=Input.Close;
if( CurrentIndex < 1 )
{
EMA1 = Input[0];
EMA2 = Input[0];
Line = 0.0;
Signal = 0.0;
KC1 = 2.0 / ((double) PFast + 1.0);
KC2 = 2.0 / ((double) PSlow + 1.0);
KC = 2.0 / ((double) PSig + 1.0);
}
else
{
EMA1 = (1.0 - KC1)*EMA1 + KC1*Input[0];
EMA2 = (1.0 - KC2)*EMA2 + KC2*Input[0];
Line = EMA1 - EMA2;
Signal = (1.0 - KC)*Signal[-1] + KC*Line;
}
if (Line[-1] > Signal[-1]&&Line[0] < Signal[0])
S.DrawArrowDown();
if (Line[-1] < Signal[-1]&&Line[0] > Signal[0])
B.DrawArrowUp();
}