Параметры
Period - период для расчета средних
Примеры работы
Исходный текст индикатора
Код: Выделить всё
function Initialize()
{
IndicatorName = "RangeChart";
PriceStudy = false;
AddInput("Input", Inputs.Candle);
AddParameter("Period", 13);
AddGlobalVariable("SUM", Types.Double, 0.0);
AddGlobalVariable("SUMR", Types.Double, 0.0);
AddSeries("Med", DrawAs.Line, Color.Red, false);
AddSeries("Range", DrawAs.Line, Color.Black, false);
AddSeries("ROpen", DrawAs.Custom, Color.Green);
AddSeries("RHigh", DrawAs.Custom, Color.Black);
AddSeries("RLow", DrawAs.Custom, Color.Black);
AddSeries("RClose", DrawAs.Custom, Color.Red);
AddSeries("Zero", DrawAs.Line, Color.Black);
}
function Evaluate()
{
// evge 31.08.2017 http://alfadirect4.ru
var I = Input;
Zero = 0.0;
double LRange = 0.0;
if (CurrentIndex > 0)
Range = Math.Max( I.Close[0] - I.Close[1], I.High[0] - I.Low[0] );
else
Range = 0;
if ( CurrentIndex < Period )
{
SUM += (I.High[0] + I.Low[0]) * 0.5;
Med = SUM / (CurrentIndex + 1);
SUMR += Range;
LRange = SUMR / (CurrentIndex + 1) / Period;
}
else
{
SUM += (I.High[0] + I.Low[0]) * 0.5 - (I.High[Period] + I.Low[Period]) * 0.5;
Med = SUM / Period;
SUMR += Range[0] - Range[Period];
LRange = SUMR / Period / Period;
}
if (LRange != 0.0) {
ROpen = ( I.Open[0] - Med[0] ) / LRange;
RHigh = ( I.High[0] - Med[0] ) / LRange;
RLow = ( I.Low[0] - Med[0] ) / LRange;
RClose = ( I.Close[0] - Med[0] ) / LRange;
}
if (RClose > ROpen)
{
ROpen.DrawHistogram(RClose);
RHigh.DrawVertical(RClose);
RLow.DrawVertical(ROpen);
}
else
{
if (RClose[0] == ROpen[0]) RClose.DrawDash(Colors["RHigh"], LineStyles.Solid, 1,0);
else RClose.DrawHistogram(ROpen);
RHigh.DrawVertical(ROpen);
RLow.DrawVertical(RClose);
}
}
Скачать исходный текст