Код: Выделить всё
function Initialize()
{
IndicatorName = "MACDSignal";
PriceStudy = false;
AddInput("Input", Inputs.Price);
AddParameter("PFast", 12);
AddParameter("PSlow", 26, 2);
AddParameter("PSig", 9);
AddSeries("Line", DrawAs.Custom, Color.Gray);
AddSeries("Signal", DrawAs.Custom, Color.Red);
AddSeries("Buy", DrawAs.Custom, Color.Green, true, Axes.Parent);
AddSeries("Sell", DrawAs.Custom, Color.Red, true, Axes.Parent);
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()
{
// AlfaDirect. 2015.
// Схождение и расхождение скользящих средних
// (MACD - Moving Average convergence & divergence).
// Автор - Джеральд Аппель (Gerald Appel).
//
// evge 09.12.2016 http://alfadirect4.ru
// Добавлены сигналы на графике Buy, Sell
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 > Signal)
Line.DrawChannel(Signal, Color.Blue, 50);
else
Line.DrawChannel(Signal, Color.Red, 50);
if (Line[1] < Signal[1] && Line[0] >= Signal[0]) { Buy = Input[0]; Buy.DrawArrowUp(); }
if (Line[1] > Signal[1] && Line[0] <= Signal[0]) { Sell = Input[0]; Sell.DrawArrowDown(); }
}