Каталог файлов форума

Список вложений в сообщениях, оставленных на этой конференции.

Все файлы форума: 1230

Добавлено: evge » 26 сен 2017, 14:43

Тема: Re: Pitchfork - вилы Эндрюса

Текст сообщения:

Ещё один вариант доработанного кода, с возможностью формирования 50% вил Эндрюса.

Добавлен новый параметр Fifty, если он не равен 0 (любое значение не равное 0), то рисуется 50%-ые вилы Эндрюса.

Как это работает и выглядит продемонстрирую на скриншоте

Pitchfork-04.png
Pitchfork-04.png (43.01 КБ) 11956 просмотров


Код: Выделить всё

function Initialize()
{
   IndicatorName = "Pitchfork";   
   PriceStudy = true;
   AddInput("Input", Inputs.Candle);   
   AddSeries("EH", DrawAs.Custom, Color.Green, true, Axes.Parent);   
   AddSeries("EL", DrawAs.Custom, Color.Red, true, Axes.Parent);
   //up rays
   AddSeries("uA", DrawAs.Custom, Color.Green, true, Axes.Parent);   
   AddSeries("uB", DrawAs.Custom, Color.Green, true, Axes.Parent);
   AddSeries("uC", DrawAs.Custom, Color.Green, true, Axes.Parent);   
   AddSeries("uD", DrawAs.Custom, Color.Green, true, Axes.Parent);
   //down rays
   AddSeries("dA", DrawAs.Custom, Color.Red, true, Axes.Parent);   
   AddSeries("dB", DrawAs.Custom, Color.Red, true, Axes.Parent);
   AddSeries("dC", DrawAs.Custom, Color.Red, true, Axes.Parent);   
   AddSeries("dD", DrawAs.Custom, Color.Red, true, Axes.Parent);

   AddParameter("Period", 15);   
   AddParameter("Scan", 200, 1);
   AddParameter("Skip", 30, 1);
   AddParameter("Fifty", 0);   // 0 - normal Pitchfork, not 0 - 50% Pitchfork
}

function Evaluate()
{
// Вилы Эндрюса
// evge 26.09.2017 http://alfadirect4.ru

//Extremums

double High = Input.High[Period];
double Low = Input.Low[Period];

bool HC = false, LC = false;

for (var x = 0; x < Period * 2; x++) {
   if (Input.High[x] > High) HC = true;
   if (Input.Low[x] < Low) LC = true;
   if (LC && HC) break;
} //x

if (!HC) EH[Period] = Input.High[Period];
if (!LC) EL[Period] = Input.Low[Period];

EH.DrawCircle();
EL.DrawCircle();

//TrendLines

if (MaxIndex == CurrentIndex) {

int    x1 = 0, x2 = 0, x3 = 0;
double    y1 = 0, y2 = 0, y3 = 0, x4 = 0, y4 = 0, y5 = 0;

for (var x = 0 + Period + Skip; x < Scan; x++) {
   if (EL[x] > 0 && y2 == 0 && y1 == 0) { y3 = EL[x]; x3 = x; continue; }   
   if (EL[x] > 0 && y3 != 0 && y2 == 0) break;

   if (EH[x] > 0 && y3 != 0) { y2 = EH[x]; x2 = x; continue; }
   if (EH[x] > 0 && y3 != 0 && y2 != 0) break;
   
   if (EL[x] > 0 && y3 != 0 && y2 != 0) { y1 = EL[x]; x1 = x; break; }
}

if (x1 > 0 && x2 > 0 && x3 > 0) {
   x4 = (x2 + x3) * 0.5;
   y4 = (y2 + y3) * 0.5;
   
   if (Fifty != 0 && y1 < y4) y1 = (y1 + y2) * 0.5;
   
   uA[x1] = y1;
   uA[0] = (double)(0 - x1) / (x4 - x1) * (y4 - y1) + y1;
   
   y5 = (double)(x2 - x1) / (x4 - x1) * (y4 - y1) + y1;
   
   uB[x2] = y2;
   uB[0] = uA[0] + (y2 - y5);
   
   uC[x3] = y3;
   uC[0] = uA[0] - (y2 - y5);
   
   uD[x2] = y2;
   uD[x3] = y3;   
}

x1 = 0; x2 = 0; x3 = 0;
y1 = 0; y2 = 0; y3 = 0; x4 = 0; y4 = 0; y5 = 0;

for (var x = 0 + Period + Skip; x < Scan; x++) {
   if (EH[x] > 0 && y2 == 0 && y1 == 0) { y3 = EH[x]; x3 = x; continue; }   
   if (EH[x] > 0 && y3 != 0 && y2 == 0) break;

   if (EL[x] > 0 && y3 != 0) { y2 = EL[x]; x2 = x; continue; }
   if (EL[x] > 0 && y3 != 0 && y2 != 0) break;
   
   if (EH[x] > 0 && y3 != 0 && y2 != 0) { y1 = EH[x]; x1 = x; break; }
}

if (x1 > 0 && x2 > 0 && x3 > 0) {   
   x4 = (x2 + x3) * 0.5;
   y4 = (y2 + y3) * 0.5;

   if (Fifty != 0 && y1 > y4) y1 = (y1 + y2) * 0.5;
      
   dA[x1] = y1;
   dA[0] = (double)(0 - x1) / (x4 - x1) * (y4 - y1) + y1;
   
   y5 = (double)(x2 - x1) / (x4 - x1) * (y4 - y1) + y1;
   
   dB[x2] = y2;
   dB[0] = dA[0] + (y2 - y5);
   
   dC[x3] = y3;
   dC[0] = dA[0] - (y2 - y5);
   
   dD[x2] = y2;
   dD[x3] = y3;   
}

} //m=c

uA.DrawLine();
uB.DrawLine();
uC.DrawLine();
uD.DrawLine();

dA.DrawLine();
dB.DrawLine();
dC.DrawLine();
dD.DrawLine();

}