[WARNING CLOSED!] Any newbie question, so as not to clutter up the forum. Professionals, don't go by. Can't go anywhere without you. - page 874

 
Andrei01:
the time of a new candle is Time[0].

and how do I further determine the arrival of a new candle?
 
reag:

and how do you further determine the arrival of a new candle?
memorise the previous one in a variable and compare it.
 
Andrei01:
memorise the previous one in a variable and compare.

I'm going to try it now...
 
reag:

and how to identify the arrival of a new candle?


There are several options, here are a couple of them:

1. when starting the Expert Advisor, remember the total number of bars on the chart and monitor the changes in the number of bars during the execution of the Expert Advisor:

//начало кода - самый верх
int counted;

int init(){
   counted=Bars;     // запомним общее количество баров на активном ТФ
    Myorders();
return(0);
}

int start(){
   Myorders();
........................

// я рассполагаю этот код в самом конце ф-ции start() - мне так удобнее
  int bar = Bars;
  if (bar != counted ) { // сравним запомненное кол-во баров с текущим если они равны тогда нет нового бара на активном ТФ
      counted= bar;
// код который необходимо выполнить по закрытию/открытию бара
  }
return(0);
}

2. remember the time of the last bar to open; the code is about the same,

use datetime last=Time[0];

and compare last==Time[0] --> if the last open time is the same as last time, if it is not equal, it means that we have a new bar

i don't know which scheme is more efficient 1 or 2 - i have doubts about the automatic downloading of history to the terminal, but i don't see any problems

 
IgorM:


There are several options, here are a couple of them:

1. when starting the Expert Advisor, remember the total number of bars on the chart and monitor the changes in the number of bars during the execution of the Expert Advisor:

this will not work. the number of bars is limited.
 
Andrei01:
it won't work. the number of bars is limited.


This works, because the total number does not matter, we are only interested in the moment when the number of bars on the chart has changed, at this moment the variable bar != counted, pay attention, I purposely remember int bar = Bars; - not to lose the value of Bars, and then compare and assign this value counted = bar; - and you could do everything with Bars without the extra variable - but I decided to double-check

I also mentioned that there may be a small kazutz during the history auto-pumping - may be it's good or may be it's bad, if we use bar open time, it will definitely work - bar open time will never change

 
IgorM:


only interested in the moment when the number of bars on the chart changed

Once the maximum value set in the settings is reached, the number of bars on the chart should not increase. although it may be that it jumps plus or minus one at the maximum, I have not checked, then it may be possible to catch it, but this is an undocumented option.
 
Andrei01:
After reaching the maximum value set in the settings, the number of bars on the chart should not increase. although it may jump, I haven't checked, then it may be possible to catch it, but this is already an undocumented option.

That was the question. I checked when the maximum is reached... Bars does not change, but stays equal to Max bars in the window (see properties).
 
reag:

that was the question. I have checked when the maximum is reached... Bars does not change, but remains equal to Max bars in the window (see properties).
Well it should be. so the first option will not work.
 
Andrei01:
Well, that's the way it should be. so the first option won't work.

Yes, the first option doesn't work, though I'm working on a non-standard timeframe, the second one does. Thank you all!