Questions from a "dummy" - page 248

 

Silent:

What - K? K is initialised as false. Assigned true along the way. Then we check - if (K). What - K?


Read the docs first.

Understand that a bool in if is not just true/false. For the compiler, anything that is not 0 is true.

https://www.mql5.com/ru/docs/basis/types/integer/boolconst

Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип bool
Документация по MQL5: Основы языка / Типы данных / Целые типы / Тип bool
  • www.mql5.com
Основы языка / Типы данных / Целые типы / Тип bool - Документация по MQL5
 
sergeev:

Read the docs for starters.

Understand that a bool in if is not just true/false. for the compiler, anything that is not 0 is true.

https://www.mql5.com/ru/docs/basis/types/integer/boolconst

Yeah, I somehow missed that point. Thanks, I'll keep it in mind.
 

Trying to get the time/price of the highlighted trend line

datetime       TL1_Old_Time,TL1_New_Time,TL2_Old_Time,TL2_New_Time;
double         TL1_Old_Prise,TL1_New_Prise,TL2_Old_Prise,TL2_New_Prise;
int            i;
string         n;

void OnStart()
  {
   if(ObjectsTotal(0,0,OBJ_TREND)<=0)
     {
      Print("-1 Trendlines не обнаружены");
      return;
     };
   for(i=ObjectsTotal(0,0,OBJ_TREND)-1;i>=0;i--)
     {
      n=ObjectName(0,i,0,OBJ_TREND);
      Print("0 Trendline "+n);
      if(ObjectGetInteger(0,n,OBJPROP_SELECTED))
        {
         TL1_Old_Prise=ObjectGetDouble(0,n,OBJPROP_PRICE,0);
         Print("TL1_Old_Prise = "+DoubleToString(TL1_Old_Prise));
         TL1_Old_Time=ObjectGetInteger(0,n,OBJPROP_TIME);
         Print("TL1_Old_Time = "+TimeToString(TL1_Old_Time));
         TL2_Old_Prise=ObjectGetDouble(0,n,OBJPROP_PRICE,0);
         Print("TL2_Old_Prise = "+DoubleToString(TL2_Old_Prise));
         TL2_Old_Time=ObjectGetTimeByValue(0,n,TL2_Old_Prise,0);
         Print("TL2_Old_Time = "+TimeToString(TL2_Old_Time));
        };
     };
  }

for

TL1_Old_Time=ObjectGetInteger(0,n,OBJPROP_TIME);

I get a warning

possible loss of data due to type conversion

But

ObjectGetInteger
Возвращает значение соответствующего свойства объекта.
Свойство объекта должно быть типов datetime, int, color, bool или char.

Question 1: how to convert correctly?

For

TL2_Old_Time=ObjectGetTimeByValue(0,n,TL2_Old_Prise,0);

I do not get the time of the second line point, but the time of the beginning of the story by the symbol

2013.05.19 17:01:52     s_Trend_Line_avto_position_1_00 (EURUSD,D1)     TL2_Old_Time = 1970.01.01 00:00

Question 2: why if

ObjectGetTimeByValue
Возвращает значение времени для указанного значения цены указанного объекта.

с

   int     line_id       // номер линии

I've done all sorts of tricks, deleted and added numbers - I don't get object time.

If you mean the line identifier - how to get it, I can't find the function.

Update

line_id

In general, it seems to relate to the indicators, then why is not reflected in the documentation. So then

ObjectGetTimeByValue

in the graphical objects section.

 

Hmm. Got rid of the warning by declaring as long

long           TL1_Old_Time,TL2_Old_Time;

It should be understood that.

ObjectGetInteger
Возвращает значение соответствующего свойства объекта в каком формате?.
Свойство объекта должно быть типов datetime, int, color, bool или char.
 
Silent:

for
TL1_Old_Time=ObjectGetInteger(0,n,OBJPROP_TIME);

I get a warning

possible loss of data due to type conversion

TL1_Old_Time=(datetime)ObjectGetInteger(0,n,OBJPROP_TIME)

such a curve in the language function

 
A100:

TL1_Old_Time=(datetime)ObjectGetInteger(0,n,OBJPROP_TIME)

such a curve in the language function

I.e., you can (and in my case should) specify a conversion for functions?

Thank you.

 
Silent:

So, it is possible (and in my case, necessary) to specify a transformation for functions?

It turns out that you should. But it is also possible to ignore warnings, which in some cases is not very convenient
 
A100:
It turns out that you should. But you can also ignore warnings, which in some cases is not very convenient

OK.

And ignore is not an option, and error log gets stuffed with anything during compilation, and potentially problematic place - so you have to look for answers :)

 

I need to get the number of bars of minutes from the high timeframe.

I get an incomprehensible number from Bars. I start it on H1 and get 1201. On M1 I get 6.

Can you tell me where the problem is?

//--- для H1
//--- переменные для указания параметров функции
   int start = 5; // индекс бара
   int count = 1; // количество баров
   int b=72000;   // секунд в H1
   int bm;        // надо получить
   datetime tm[]; // массив, в котором возвращается время баров
//--- копирование времени 
   CopyTime(_Symbol,PERIOD_CURRENT,start,count,tm);
//--- вывод результата
   Print(tm[0]);

   bm=Bars(_Symbol,PERIOD_M1,tm[0]+b,tm[0]);
   Print("bm = "+bm);
//--- возвращает bm = 1201
   bm=Bars(_Symbol,PERIOD_M1,tm[0]-b,tm[0]);
   Print("bm = "+bm);
 
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   int start=5;
   int count=2;
   datetime _time[];
   datetime _timeM1[];
   int ntime=CopyTime(_Symbol,_Period,start,count,_time);//узнаем время 5 и 4 бара, нумерация как в тайм серии
   if(ntime>0)
     {
      Print("_time[0]=",_time[0]);
      Print("_time[1]=",_time[1]);
      
      datetime endtime=_time[1]-PeriodSeconds(PERIOD_M1);
      int nM1=CopyTime(_Symbol,PERIOD_M1,_time[0],endtime,_timeM1);//получаем массив содержащий время минуток и число минуток
      if(nM1>0)
       {
        Print("Число минуток в период с ",_time[0]," по ",endtime," =",nM1);
       }
      int nbarsM1=Bars(_Symbol,PERIOD_M1,_time[0],endtime);//проверимся
      Print("Число минуток =",nbarsM1);
     }
  }
//+------------------------------------------------------------------+

You can do that.

And you have a lot of seconds in an hour, as much as 72,000! I wish I had that many in reality )).

In real code, you still need to check the synchronisation of the smaller timeframe.

Reason: