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

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

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

Добавлено: evge » 15 авг 2020, 09:21

Тема: Re: RangeOfHours - экстремумы предыдущих часов

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

Вариация с отображением в виде баров на графике от таймфрейма Hours

RangeHours-06.png
GZU0, График с таймфреймом H1
RangeHours-06.png (26.37 КБ) 34177 просмотров

RangeHours-05.png
GZU0, RangeHoursBars, Hours = 1, Таймфрейм M5
RangeHours-05.png (40.91 КБ) 34177 просмотров

RangeHours-04.png
GZU0, RangeHoursBars, Hours = 1, Таймфрейм M5
RangeHours-04.png (42.99 КБ) 34178 просмотров

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

function Initialize()
{
  IndicatorName = "RangeHoursBars";
  AddInput("Input", Inputs.Candle);   
  PriceStudy = true;
  AddSeries("H", DrawAs.Custom, Color.Black);
  AddSeries("L", DrawAs.Custom, Color.Black);
  AddSeries("Ou", DrawAs.Custom, Color.Green);
  AddSeries("Cu", DrawAs.Custom, Color.Green);   
  AddSeries("Od", DrawAs.Custom, Color.Red);
  AddSeries("Cd", DrawAs.Custom, Color.Red);   
  AddSeries("Mid", DrawAs.Custom, Color.Silver);  // средняя цена
  AddParameter("MinScan", 163, 2); // подзагрузка истории количество 5-минутных баров
  AddParameter("Hours", 1); // кол-во часов
  AddGlobalVariable("High", Types.Double, 0);
  AddGlobalVariable("Low", Types.Double, 0);
  AddGlobalVariable("Open", Types.Double, 0);
  AddGlobalVariable("Close", Types.Double, 0); 
  AddGlobalVariable("LastHigh", Types.Double, 0);
  AddGlobalVariable("LastLow", Types.Double, 0);
  AddGlobalVariable("SI", Types.Int, 0);
  AddGlobalVariable("SIO", Types.Int, 0);
  AddGlobalVariable("HRS", Types.Double, 0);
}

function Evaluate()
{
// evge 27.04.2020 https://alfadirect4.ru
//   RangeHours - Индикатор рисует экстремумы предыдущих часов и текущего часа, в зависимости от параметров, продолжая экстремумы предыдущего часа (кол-ва часов Hours) или расчитывая в текущем часе динамически.
//   14.08.2020 добавлен параметр Hours, где можно задать количество часов для вычисления диапазона.
//   14.08.2020 добавлен пересчет часов под реальный таймфрейм. Для совпадения показаний индикатора с данными графика в указанном таймфрейме (в часах) H1, H2, H3, H4, H6, H8, H12
//   15.08.2020 отрисовка в виде баров часовых таймфремов Hours

bool isH = false;

int[] HH = {0,0,0,1,2,0,4,0,2,0,0,0,10};

//первая свечка часа
//сохранаем текущий индекс и последние найденные High, Low
if ( BarTime().Hours != BarTime(1).Hours)
   {
   bool NewDay = BarTime(0).Hours < BarTime(1).Hours;
   HRS = BarTime(0).Hours > BarTime(1).Hours ? HRS + BarTime(0).Hours - BarTime(1).Hours : Hours > 0 && Hours <= 12 ? HH[(int)Hours] : BarTime(0).Hours;
   if (HRS >= Hours || NewDay)
      {
         isH = true;
      if (!NewDay) HRS = 0;
      SIO = SI;
      SI = CurrentIndex;
      LastHigh = High;
      LastLow = Low;
   
      //перерисовываем
      if (SIO != 0)
      for (var x=0; x <= CurrentIndex - SIO; x++)
      {
       Mid[x] = (Open + Close) * 0.5;
      if (Math.Round((CurrentIndex - SIO) * 0.5) == x)
         {
         H[x] = High;
            L[x] = Low;
         } else
      {
         H[x] = Mid[x];
            L[x] = Mid[x];
         }         
      Ou[x] = Mid[x];
      Cu[x] = Mid[x];
      Od[x] = Mid[x];
      Cd[x] = Mid[x];
       if (Close > Open)
          {
         Ou[x] = Open;
            Cu[x] = Close;
         }
       if (Close < Open)
          {
         Od[x] = Open;
            Cd[x] = Close;
         }
            
      }
      }
   }

if (isH)
  {
    High = Input.High[0];
    Low = Input.Low[0];
    Open = Input.Open[0];
    Close = Input.Close[0]; 
  }
  else if (BarTime() > AsTime(0, 0, 0))
  {
    if ( Input.High[0] > High) High = Input.High[0];
    if ( Input.Low[0] < Low) Low = Input.Low[0];
    Close = Input.Close[0];
  }

if (SI != 0)
for (var x=0; x <= CurrentIndex - SI; x++)
{
Mid[x] = (Open + Close) * 0.5;
if (Math.Round((CurrentIndex - SI) * 0.5) == x)
   {
      H[x] = High;
      L[x] = Low;
   }
   else
   {
   H[x] = Mid[x];
   L[x] = Mid[x];
   }
Ou[x] = Mid[x];
Cu[x] = Mid[x];
Od[x] = Mid[x];
Cd[x] = Mid[x];
if (Close > Open)
   {
      Ou[x] = Open;
      Cu[x] = Close;
   }
if (Close < Open)
   {
      Od[x] = Open;
      Cd[x] = Close;
   }
}

H.DrawVertical(L);
if (!isH)
{
   Ou.DrawChannel(Cu);
   Od.DrawChannel(Cd);   
}

}