Входящие параметры
Risk - В основе индикатора лежит осциллятор WPR, данный параметр одновременно влияет на его период и уровни. Чем больше Risk, тем меньше сигналов. Максимум 32.
Примеры
Код: Выделить всё
function Initialize()
{
   IndicatorName = "ASCTrend";
   PriceStudy = true;
   AddInput("Input", Inputs.Candle);
    AddSeries("Sell", DrawAs.Custom, Color.Red);
    AddSeries("Buy", DrawAs.Custom, Color.Green);
    AddSeries("wpr1", DrawAs.Line, Color.Black, false);
   AddSeries("wpr2", DrawAs.Line, Color.Black, false);
    AddParameter("Risk", 25);
   AddGlobalVariable("Whait", Types.Int, 0);
   AddGlobalVariable("RangeSum", Types.Double, 0);
}
function Evaluate()
{
// evge 05.06.2019 https://alfadirect4.ru
var I = Input;
int defaultPeriod = 3 + Risk * 2;
int UpperLevel = 67 + Risk;
int LowerLevel = 33 - Risk;
int RangePeriod = 10;
if (CurrentIndex < RangePeriod) 
   { 
   RangeSum += I.High[0] - I.Low[0];
   return;
   }
   
RangeSum += -(I.High[RangePeriod] - I.Low[RangePeriod]) + (I.High[0] - I.Low[0]);
double Range = RangeSum / RangePeriod;
if (CurrentIndex < defaultPeriod) return;   
double H1 = 0, H2 = 0, L1 = Double.MaxValue, L2 = Double.MaxValue;
for (int i = 0; i < defaultPeriod; i++)
{
   if (I.High[i] > H1) H1 = I.High[i];
   if (I.Low[i] < L1) L1 = I.Low[i];
   if (i < 4) 
   {
      if (I.High[i] > H2) H2 = I.High[i];
      if (I.Low[i] < L2) L2 = I.Low[i];
   }
}
if ((H1 - L1) != 0)
   wpr1[0] = -100 * ((H1 - I.Close[0]) / (H1 - L1));
   else 
   wpr1[0] = -100 * (H1 - I.Close[0]);
if ((H2 - L2) != 0)
   wpr2[0] = -100 * ((H2 - I.Close[0]) / (H2 - L2));
   else 
   wpr2[0] = -100 * (H2 - I.Close[0]);
double Indicator = wpr2[0];
for (int j = 0; j < 6; j++)
   {
   if (Math.Abs(I.Close[j + 3] - I.Close[j]) >= Range * 4.6)
      {
      Indicator = wpr1[0];
      break;
      }
   }
Indicator = 100 - Math.Abs(Indicator);
if (Indicator < LowerLevel)
   {
   if (Whait == -1) 
      {
      Sell[0] = I.High[0];
      Sell.DrawArrowDown();
      }
   Whait = 1;
   }
if (Indicator > UpperLevel)
   {
   if (Whait == 1) 
      {
      Buy[0] = I.Low[0];
      Buy.DrawArrowUp();
      }
   Whait = -1;
   }
}
Скачать индикатор

 
  ))
))