Код: Выделить всё
function Initialize()
{
IndicatorName = "ATRs";
AddInput("Input", Inputs.Candle);
PriceStudy = false;
AddParameter("Period", 10);
AddParameter("Smooth", 3);
AddSeries("ATR", DrawAs.Line, Color.Red);
}
function Evaluate()
{
// AlfaDirect. 2014. OX
// Средний истинный диапазон (ATR - Average True Range).
// Автор - Уэллс Уайлдер (Welles Wilder).
// evge 26.11.2019 https://alfadirect4.ru
// add smooth
var TR = 0.0;
if (CurrentIndex < 1)
ATR = Input.High[0]-Input.Low[0];
else
{
TR = ( Math.Max(Input.High[0] , Input.Close[-1]) - Math.Min(Input.Low[0], Input.Close[-1]));
var TR1 = ( Math.Max(Input.High[1] , Input.Close[-2]) - Math.Min(Input.Low[1], Input.Close[-2]));
if (TR > TR1 * Smooth) TR = TR1;
ATR = ((Period-1.0)*ATR[-1] + TR)/Period;
}
}