Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 979

 
paladin80:

Continuing the conversation... As I understand it, the assignment can be reduced to the following. To simplify, we will only examine yesterday's day, H1 period.

First, we look for the earliest candle (looking from the left side of the yesterday's chart) the Close of which is higher than the Open, i.e. we look for the first bullish candle. If this one is found, then starting from it (including it) to the latest candle of the current day, we should find the candle with the highest High. E.g., if the opening time of the first bullish candle is 10:00, then from it till the 23:00 candle we should look for the candle with the highest High. Right?

Oh, thank goodness... I got it! YES! YEAH! YES! That's exactly what I'm trying to do. If you know, can you tell me how to do it?
 
Vadim_2015:
Oh, thank goodness... I'm understood! YES! YES! YES! That's exactly what I'm trying to do. If you know, can you tell me how to do it?
Understood, I'll try to think about it, but it depends on current affairs. If you have any questions in the future, please put them in a way that makes it easier for the programmers to understand.
 
Vadim_2015:
Oh, thank goodness... I got it! YES! YES! YES! That's exactly what I'm trying to do. If you know, can you tell me how to do it?

If it is yesterday's candlestick, it will be the end candlestick in iHigest(), and the start candlestick will be 00:00 of the next day (i.e. today's candlestick) obtained from iBarShift().

Example algorithm:

1. Today we are looking for the first bull bar among yesterday's hour bars. Let it be the endBar index

Determine the first one-hour bar today. Or it will be zero.

3. In iHighest() set the penultimate parameter as endBar (or endBar +1 should be precise), and the last one as 1.

The sought result is High[iHighest(with relevant parameters)] // Or the corresponding variable, the value of which was assigned in the previous clause.

 
Vadim_2015:
Oh, thank goodness... I'm understood! YES! YES! YES! That's exactly what I'm trying to do. If you know, can you tell me how to do it?
void OnStart()
  {
 double  longValue;
 datetime t1,t2;    
 int b1,b2,h; 
 
 int bStart = iBarOfDayReal();//бар, с которого уходим в историю
          Print("",bStart);                 
   for(int i=bStart;i<bStart+1000;i++)
      {
       longValue = Close[i+1]-Open[i+3];
       
//--- само условие
         
       if(longValue>0) 
       {
      t1= iTime(NULL,0,i); //
      t2= iTime(NULL,PERIOD_D1,iBarShift(NULL,PERIOD_D1,t1,false)-1);//00.00.00 время 
      
     // Print("",TimeToStr(t1,TIME_DATE|TIME_SECONDS)); 
     // int("",TimeToStr(t2,TIME_DATE|TIME_SECONDS))Pr;
     
      b1= iBarShift(NULL,0,t1,false);
      b2= iBarShift(NULL,0,t2,false); 
      
      h=iHighest(NULL,0,MODE_HIGH,b1-b2+1,b2);//нашли максимум
      
      SetArrow(159,clrCoral,"h"+(string)Time[h],Time[h],High[h]); //рисуем пипичку
     
       }
   }
  }
//+------------------------------------------------------------------+
void SetArrow(int cd, color cl,
              string nm="", datetime t1=0, double p1=0, int sz=0) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[0];
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_ARROW, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1    , t1);
  ObjectSet(nm, OBJPROP_PRICE1   , p1);
  ObjectSet(nm, OBJPROP_ARROWCODE, cd);
  ObjectSet(nm, OBJPROP_COLOR    , cl);
  ObjectSet(nm, OBJPROP_WIDTH    , sz);
}
//-------------------------------------------------------------------+
int iBarOfDayReal(string sy="", int tf=0, datetime dt=0) {
  if (sy=="" || sy=="0") sy=Symbol();
  if (tf<=0) tf=Period();
  if (dt<=0) dt=TimeCurrent();
  if (tf>PERIOD_D1) {
    Print("iBarOfDayReal(): Таймфрейм должен быть меньше или равен D1");
    return(0);
  }

  int cd=TimeDay(dt);                       // текущий день месяца
  int nb=iBarShift(sy, tf, dt, False);      // номер текущего бара
  int bd=0;                                 // номер бара от начала суток

  while(TimeDay(iTime(sy, tf, nb))==cd) {
    nb++;
    bd++;
  }

  return(bd);
}
   
  
//+------------------------------------------------------------------+
SCRIPT! try it.
 
r772ra:
SCREPT! trying.

r772ra Thank you very much!!! The script does what I need!!! Not everything is clear to me in the last block of code, but I'll figure it out. I will figure it out. I will try to use it in indicator.

Iwill try to use it in an indicator:

If you have any questions in the future, please put them in a way that makes it easier for the programmers to understand.

I got it, I will take it into account!

Thank you very much!

 
Vadim_2015:

r772ra Thank you very much!!! The script does what I need!!! Not everything is clear to me in the last block of code, but I'll figure it out. I will figure it out. I will try to apply it to indicator.

All right, I will take it into account!

Thank you very much!

Exactly what is not clear?
 
r772ra:
Exactly what is not clear?

Explain if I'm wrong, I think the second half of the script code _"void SetArrow(int cd, color cl," is the part that refers to the"_OnInit()" function in the indicator.. indicator, and the first part of the script _"void OnStart()" refers to the function "_OnCalculate" in the indicator? I mean, roughly speaking, the script has 1) calculation at first and then 2) initialization only. In the indicator it is vice versa.

 
Vadim_2015:

Explain if I'm wrong, I think the second half of the script code _"void SetArrow(int cd, color cl," is the part that refers to the"_OnInit()" function in the custom indicator.. indicator, and the first part of the script _"void OnStart()" refers to the function "_OnCalculate" in the indicator? I mean, roughly speaking, the script has 1) calculation at first and then 2) initialization only. In the indicator it is vice versa.

It is a user-defined function that is outside the scope of other functions.

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 12.10.2007                                                     |
//|  Описание : Установка значка на графике, объект OBJ_ARROW.                 |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    cd - код значка                                                         |
//|    cl - цвет значка                                                        |
//|    nm - наименование               ("" - время открытия текущего бара)     |
//|    t1 - время открытия бара        (0  - текущий бар)                      |
//|    p1 - ценовой уровень            (0  - Bid)                              |
//|    sz - размер значка              (0  - по умолчанию)                     |
//+----------------------------------------------------------------------------+
void SetArrow(int cd, color cl,
              string nm="", datetime t1=0, double p1=0, int sz=0) {
  if (nm=="") nm=DoubleToStr(Time[0], 0);
  if (t1<=0) t1=Time[0];
  if (p1<=0) p1=Bid;
  if (ObjectFind(nm)<0) ObjectCreate(nm, OBJ_ARROW, 0, 0,0);
  ObjectSet(nm, OBJPROP_TIME1    , t1);
  ObjectSet(nm, OBJPROP_PRICE1   , p1);
  ObjectSet(nm, OBJPROP_ARROWCODE, cd);
  ObjectSet(nm, OBJPROP_COLOR    , cl);
  ObjectSet(nm, OBJPROP_WIDTH    , sz);
}

Functioncall, from any other function

SetArrow(159,clrCoral,"h"+(string)Time[h],Time[h],High[h]); //рисуем пипичку

I think you don't need it in the indicator, the buffer is responsible for the drawing

In other words.

          longBarsBuffer[i]=High[h]+5*Point(); - то что необходимо получить. 
       else 
          longBarsBuffer[i]=0.0; 

Further

The function

//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 26.02.2008                                                     |
//|  Описание : Возвращает реальный номер бара от начала суток.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    sy - наименование инструмента   (NULL или "" - текущий символ)          |
//|    tf - таймфрейм                  (          0 - текущий таймфрейм)       |
//|    dt - дата и время открытия бара (          0 - текущее время)           |
//+----------------------------------------------------------------------------+
int iBarOfDayReal(string sy="", int tf=0, datetime dt=0) {
  if (sy=="" || sy=="0") sy=Symbol();
  if (tf<=0) tf=Period();
  if (dt<=0) dt=TimeCurrent();
  if (tf>PERIOD_D1) {
    Print("iBarOfDayReal(): Таймфрейм должен быть меньше или равен D1");
    return(0);
  }

  int cd=TimeDay(dt);                       // текущий день месяца
  int nb=iBarShift(sy, tf, dt, False);      // номер текущего бара
  int bd=0;                                 // номер бара от начала суток

  while(TimeDay(iTime(sy, tf, nb))==cd) {
    nb++;
    bd++;
  }

  return(bd);
}

And the call

find the number of bars from the beginning of the day (the current day is not recalculated) and that bar goes into the history.

 int bStart = iBarOfDayReal();//бар, с которого уходим в историю
 
Addendum))) the functions are taken from here
 
r772ra:
Addendum))) the functions are taken from here

Wow, that's a lot to chew on:) ...As they say, -No more questions -no more questions!

THANK YOU!!!