Добавлено:
- Отображение лучей для восходящих максимумов и нисходящих минимумов фракталов
- Возможность задать отступ для сканирования, параметр "Skip";
Пример. Несколько индикаторов TrendLines2 с разными параметрами:
Набросок не оптимальный по обходу истории, но работающий:
Код: Выделить всё
function Initialize()
{
IndicatorName = "TrendLines2";
PriceStudy = true;
AddInput("Input", Inputs.Candle);
AddSeries("EH", DrawAs.Custom, Color.Green, true, Axes.Parent);
AddSeries("EL", DrawAs.Custom, Color.Red, true, Axes.Parent);
AddSeries("Up", DrawAs.Custom, Color.Green, true, Axes.Parent);
AddSeries("Down", DrawAs.Custom, Color.Red, true, Axes.Parent);
AddSeries("Up2", DrawAs.Custom, Color.Green, true, Axes.Parent);
AddSeries("Down2", DrawAs.Custom, Color.Red, true, Axes.Parent);
AddParameter("Period", 15);
AddParameter("Scan", 200, 3);
AddParameter("Skip", 20, 3);
}
function Evaluate()
{
//evge 04.02.2016, http://alfadirect4.ru
//evge 15.09.2017
// + добавлено отображение лучей для восходящих максимумов и нисходящих минимумов фракталов
// + добавлена возможность задать отступ для сканирования, параметр "Skip";
//Extremums
var High = Input.High[Period];
var Low = Input.Low[Period];
var HC = 1;
var LC = 1;
for (var x = 0; x < Period * 2; x++) {
if (Input.High[x] > High) HC = 0;
if (Input.Low[x] < Low) LC = 0;
if (LC == 0 && HC == 0) break;
} //x
if (HC > 0) EH[Period] = Input.High[Period];
if (LC > 0) EL[Period] = Input.Low[Period];
EH.DrawCircle();
EL.DrawCircle();
//TrendLines
if (MaxIndex == CurrentIndex) {
var x1 = 0;
var x2 = 0;
var y1 = 0.0;
var y2 = 0.0;
for (var x = 0 + Period + Skip; x < Scan + Skip; x++) {
if (EH[x] > 0 && y2 == 0) { y2 = EH[x]; x2 = x; x+=Period-1; }
if (EH[x] > 0 && y2 != 0 && y1 == 0 && y2 > EH[x]) break;
if (EH[x] > 0 && y2 != 0 && y1 == 0) { y1 = EH[x]; x1 = x; break; }
}
if (x1 > 0 && x2 > 0) {
Down[x1] = y1;
Down[0] = (double)(0 - x1) / (x2 - x1) * (y2 - y1) + y1;
}
x1 = 0;
x2 = 0;
y1 = 0.0;
y2 = 0.0;
for (var x = 0 + Period + Skip; x < Scan + Skip; x++) {
if (EL[x] > 0 && y2 == 0) { y2 = EL[x]; x2 = x; x+=Period-1; }
if (EL[x] > 0 && y2 != 0 && y1 == 0 && y2 < EL[x]) break;
if (EL[x] > 0 && y2 != 0 && y1 == 0) { y1 = EL[x]; x1 = x; break; }
}
if (x1 > 0 && x2 > 0) {
Up[x1] = y1;
Up[0] = (double)(0 - x1) / (x2 - x1) * (y2 - y1) + y1;
}
x1 = 0;
x2 = 0;
y1 = 0.0;
y2 = 0.0;
for (var x = 0 + Period + Skip; x < Scan + Skip; x++) {
if (EL[x] > 0 && y2 == 0) { y2 = EL[x]; x2 = x; x+=Period-1; }
if (EL[x] > 0 && y2 != 0 && y1 == 0 && y2 > EL[x]) break;
if (EL[x] > 0 && y2 != 0 && y1 == 0) { y1 = EL[x]; x1 = x; break; }
}
if (x1 > 0 && x2 > 0) {
Down2[x1] = y1;
Down2[0] = (double)(0 - x1) / (x2 - x1) * (y2 - y1) + y1;
}
x1 = 0;
x2 = 0;
y1 = 0.0;
y2 = 0.0;
for (var x = 0 + Period + Skip; x < Scan + Skip; x++) {
if (EH[x] > 0 && y2 == 0) { y2 = EH[x]; x2 = x; x+=Period-1; }
if (EH[x] > 0 && y2 != 0 && y1 == 0 && y2 < EH[x]) break;
if (EH[x] > 0 && y2 != 0 && y1 == 0) { y1 = EH[x]; x1 = x; break; }
}
if (x1 > 0 && x2 > 0) {
Up2[x1] = y1;
Up2[0] = (double)(0 - x1) / (x2 - x1) * (y2 - y1) + y1;
}
} //m=c
Down.DrawLine();
Up.DrawLine();
Down2.DrawLine();
Up2.DrawLine();
}