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

 
PolarSeaman:

Is it, current time subtract the opening time of the bar?

//+------------------------------------------------------------------+
//| Количество секунд, остающихся до закрытия свечи                  |
//+------------------------------------------------------------------+
long SecondsToCandleClose(const string symbol_name,const ENUM_TIMEFRAMES timeframe)
  {
   datetime array[];
   return(CopyTime(symbol_name,timeframe,0,1,array)==1 ? PeriodSeconds(timeframe)+array[0]-TimeCurrent() : 0);
  }
//+------------------------------------------------------------------+
 
PolarSeaman:

can OnCalculate() be inserted into OnTimer()?

I don't know how to synchronise local andcurrent time, I can't find it in the help.

These are two different event handlers. OnCalculate() is triggered by a new tick, OnTimer() is triggered by the time that is set when you start the timer.

 
PolarSeaman:

how, not to do? only this minute you have to check, and sleep for 24 hours)

Then you can't do without a timer.

 
Artyom Trishkin:

Thank you. now we need to make it work, as who, in the absence of a tic.

        if(SecondsToCandleClose(Symbol(),0)<=60)
              {
               if(open[i]>close[i] && high[i]-low[i]>=100*Point)
                 {
                  BufferUP[i]=low[i]-distance*Point;
                 }
              }
 
PolarSeaman:

can OnCalculate() be inserted into OnTimer()?

I don't know how to synchronise local andcurrent time, can't find it in help.

At the moment of a tick we count the difference TimeCurrent()-TimeLocal()
- this is our offset relative to the broker; if this offset changes later, everything should be recalculated
- at the start or appearance of bar D1, recalculate all the necessary times, to the local time
- we wait for the time we have "counted" in the timer, at the same time check for unsynchronization, disconnection with the broker, re-set the local arrows.

 
Ihor Herasko:

These are two different event handlers. OnCalculate() is triggered by a new tick, OnTimer() is triggered by the time that is set when the timer is started.

Thanks, I see. Can the indicator work in OnTimer() ?

 
PolarSeaman:

Thank you. Now we need to make it work in the absence of a tick.

The code should be inserted into OnTimer(). But, again, it cannot be used on history. So put 0 instead of i right away.

 
PolarSeaman:

Thank you, I see. Can the indicator work in OnTimer() ?

The OnTimer() event works in the indicator. But you should not put the whole code into OnTimer(). There should be only the part responsible for tracking the time left till the end of the candle. Everything else must work in OnCalculate().

 
Taras Slobodyanik:

the moment the tic comes on...

Well... What if the tick doesn't come? It needs to "start" without the tick.

 
Ihor Herasko:

But, again, you can't use it on a story.

Sorry, I don't understand why you can't.

Reason: