How do I get Open,Low,High,Close parameters in MQL5? - page 5

 
Igor Makanu:

you can either class CNewbar, or search the forum for NewBar


You have an iTime call in your class. I was advised to forget about it). Besides, where's the guarantee that it's not doing the same job as CopyRates? You call it on every tick. In short, I will call CopyRates on every tick and the issue is closed.

 
Artyom Trishkin:

Yes, on every tick we check the time:

And in a nutshell:

just writing on my knees - to show the idea, not the accuracy of the writing

There is no point in calculating a new bar if the calculation itself involves CopyRates or its counterpart. The same expenses will be.

I'll call in every tick. Oops.

 
Igor Makanu:

you can either class CNewbar, or search the forum for NewBar

ZS: whole article!https://www.mql5.com/ru/articles/159



OK, the usual...oops, oops, oops...and not a single line of code ))))

I cited my example to show that it's not always convenient (and seldom necessary) to obtain an array of consecutive OHLC. In practical problems, you usually need to get a selection of OHLC values from different bars (indicators are not taken into account)

Ok, don't be ill!

Oh, come on. Fat people are most often warm. That's why you can use these comparisons too. Who cares if you need OHLC... Igor said you should use fractals, so use them...

 
Реter Konow:

You have iTime call in your class. I was advised to forget about it). Besides, where's the guarantee that it's not doing the same job as CopyRates? You call it on every tick. Anyway, I call CopyRates on every tick and the issue is closed.

This is longer than calling CopyTime() or iTime() once per tick.

CopyRates() is called only when you need to get all values of bar at once - at the moment of new bar definition.

 
Реter Konow:
There is no point in calculating a new bar if the calculation itself involves CopyRates or its counterpart. The same expenses will be.

I'll call in every tick. Spas.

Answer - you are wrong.

 
Artyom Trishkin:

This is longer than calling CopyTime() or iTime() once per tick.

Call CopyRates() only when you need to get all bar values at once - at the moment of defining a new bar.

Ok. So the setting to forget about iXXX functions must be forgotten.)

 
Реter Konow:

Ok. So you must forget about iXXX functions)).

Of course. Not everything is useful what they say. And I can say such rubbish :)))

But here - for speed reasons: CopyRates() is useful when you need to get several values of one bar simultaneously (your case). It is slower than CopyTime() or iTime(), but if you call CopyOpen(), CopyHigh(), CopyLow() and CopyClose() + (CopyTime() if necessary), then it will be slower than the singlecall CopyRates(), which will return all the required values at once.

Conclusion: on each tick we work with CopyTime() or iTime() to determine a new bar, and at the moment of appearance of a new bar we call CopyRates() once.

And you should not take into account religious statements, which are not confirmed by anything but belief. You can check yourself what would be faster for your case of defining a new bar - CopyTime() or iTime() - recently implemented in MQL5 function, that facilitates writing cross-platform code (there's a lie - since MQL4 also contains CopyXXX functions, but the porting of MQL4 code in MQL5 is easier - you do not need iXXX functions to redo)

 
Реter Konow:
Otherwise, how would you know that the opening time of the current bar has changed?
//+------------------------------------------------------------------+
//|                                                       NewBar.mq5 |
//|                        Copyright 2019, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"

MqlDateTime time;

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
{

   EventSetMillisecondTimer(100);
   return(INIT_SUCCEEDED);
}

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
   EventKillTimer();   
}

//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
{

   
}

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
{
   TimeGMT(time);   
   //TimeLocal(time);

   if(NewMinute())
   {
     Print("Я новая минута");
   }		
}

//####################################################################

//Получить новое время
int zero = 0;
bool NewMinute()
{
  int minute = time.min; //time.sec; time.hour;  time.day; 
  if(zero != minute)
  {    
    zero = minute;
    return(true);
  }
  else return(false); 
}
 
Реter Konow:

You have iTime call in your class. I was advised to forget about it). Besides, where's the guarantee that it in its turn doesn't do the same job as CopyRates? You call it on every tick. Anyway, I call CopyRates on every tick and the issue is closed.

Do you always just write and don't try to read? I gave you a link to a whole article about the New Bar! Articles are checked - checked by people of a different competence than those who write constantly on the forum ;)

ZS: If you stop writing and start reading, such as the article on my link, you can find another way (SERIES_LASTBAR_DATE ) not to use the iXXX() - I told you not to use them ))) - Who would report bugs and errors, that developers released shoddy )))))

 
Igor Makanu:

Do you always just write and don't try to read? I gave you a link to a whole article about the New Bar! Articles are checked - checked by people of a different competence than those who write constantly on the forum ;)

ZS: If you stop writing and start reading, such as the article on my link, you can find another way ( SERIES_LASTBAR_DATE ) not to use the iXXX() - I told you not to use them ))) - who would tell the bugs and errors that the developers released shoddy )))))

There were some problems with SERIES_LASTBAR_DATE. It was discussed here somewhere a long time ago. Maybe it was fixed.