Пример
Код: Выделить всё
function Initialize()
{
IndicatorName = "eEMA";
AddInput("Input", Inputs.Price);
AddSeries("EMA", DrawAs.Custom, Color.Black);
AddSeries("Up", DrawAs.Custom, Color.Green);
AddSeries("Down", DrawAs.Custom, Color.Red);
PriceStudy = true;
AddParameter("Period", 20, 1);
AddGlobalVariable("K", Types.Double, 0.0);
}
function Evaluate()
{
// AlfaDirect. 2015. OX
// EMA - экспоненциальная скользящая средняя.
// модификация evge 24.03.2016, http://alfadirect4.ru
if (CurrentIndex > 0)
EMA = (1.0 - K)*EMA[-1] + K*Input[0];
else
{
EMA = Input[0];
K = 2.0/(Period + 1.0);
}
if (EMA[0] < EMA[1])
{ Down[1] = EMA[1]; Down[0] = EMA[0]; Down.DrawLine(); }
else
{ Up[1] = EMA[1]; Up[0] = EMA[0]; Up.DrawLine(); }
}