Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 364

 

Is it possible to make a table in MT4 with a structure like in Excel (+ and - collapses and unfolds the data)? If so, where can I read about it?


 

Hi all! I'm just learning the codes. There is an error, I can't figure out how to fix it.


int CountTrades(int type, int magic)

{

int count=0;

for(int i=OrdersTotal()-1;i>=0;i-)

{

if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))

{

if(OrderSymbol()==Symbol() && (OrderType()==type||type==-1) &&

(OrderMagicNumber()==magic||magic==-1))

count++;

}

}

return (count);


I've highlighted what it misses.


The errors are as follows:

"-" operand expected

")" - unexpected token

"i" - undeclared identifier


It's like he doesn't like that I put minus after i in the first error. Maybe I should hyphenate it somehow?

I did it all letter by letter with the tutorial - but the code does not compile.

I need your help.

 
Falx:

Hi all! I'm just learning the codes. There's a bug, can't figure out how to fix it.

Two minuses and no bracket to close the function.
 
Aleksey Vyazmikin:
Two minuses and no brackets to close the function.

Thank you very much! All fixed! It's working!

 

I had to compare the two datetime by hours, I did it this way:

string TimeCompare = StringSubstr(TimeToString(MyLastNewsTime[i],TIME_DATE|TIME_MINUTES),0,13);
string TimeCompare1 = StringSubstr(TimeToString(MyLastNewsTime1[i],TIME_DATE|TIME_MINUTES),0,13);
if(TimeCompare != TimeCompare1)
...

It worked, but maybe this is not the most correct way? What do the programmers have to say?

 
Nauris Zukas:

I had to compare the two datetime by hours, I did it this way:

It worked, but maybe this is not the most correct way? What do the programmers have to say?


if(TimeHour(MyLastNewsTime[i])!=TimeHour(MyLastNewsTime1[i]))
 {
 }
 
Nikolay Ivanov:

Maybe I didn't explain it correctly, but you need to find two dates to the exact hour (minutes and seconds are not important). You only have a comparison by hours.

 
Nauris Zukas:

Maybe I didn't explain it correctly, but you need to find two dates to the exact hour (minutes and seconds are not important).


you need to find dates, or compare the hour of 2 dates ?

 
Nikolay Ivanov:

find dates, or compare the hour of 2 dates ?

You need to find dates to the exact hour (minutes and seconds are not important).

 
Nikolay Ivanov:

you have to find the dates, or compare the hour of 2 dates ?

Would CopyTime work better?

This way.

int  CopyTime(
   string           symbol_name,     // имя символа
   ENUM_TIMEFRAMES  timeframe,       // период PERIOD_H1
   datetime         start_time,      // с какой даты
   int              count,           // сколько копируем 1
   datetime         time_array[]     // массив для копирования времени открытия
   );

Translating time into a string and comparing it is not a good option.

CopyTime - Доступ к таймсериям и индикаторам - Справочник MQL4
CopyTime - Доступ к таймсериям и индикаторам - Справочник MQL4
  • docs.mql4.com
Функция получает в массив time_array исторические данные времени открытия баров для указанной пары символ-период в указанном количестве. Необходимо отметить, что отсчет элементов от стартовой позиции ведется от настоящего к прошлому, то есть стартовая позиция, равная 0, означает текущий бар. При копировании заранее неизвестного количества...
Reason: