Help!

 
How to prescribe that at the opening of a candle an order was opened, and at the opening of the next one it was closed and a new one was opened!
 
Anton Tarasov:
How do I specify that at the opening of a candle an order is opened, and at the opening of the next one it is closed and a new one is opened!
The first thing to do is to specify the platform.
 
Alexey Kozitsyn:
First you need to specify the platform.
Mt4
 
Anton Tarasov:
Mt4

Here is the function for determining the start of a new bar

/// Определяет начало нового бара
bool NewBar()
{
    static datetime lastbar = 0;
    datetime curbar = iTime(Symbol(), PERIOD_M1, 0);
    if(lastbar!=curbar)
    {
        lastbar=curbar;
        return (true);
    }
    return(false);
}
 
Alexey Volchanskiy:

Here's a function to determine the start of a new bar

Thank you!

 
Alexey Volchanskiy:

Here is a function for determining the start of a new bar

this is not the right function!!!

It will give one false signal on the first run of the EA

This is the correct and reliable way :

// =========================================================================================================// 
bool NewBar()
  {
   static datetime time=0;
   datetime cur_time = iTime(Symbol(), PERIOD_CURRENT, 0);
   if(time==0)
     {
      time=cur_time;
      return false;
     }
   if(time!=cur_time)
     {
      time=cur_time;
      return true;
     }
   return false;
  }
// =========================================================================================================//
 
Vladimir Pastushak:

this is not the right function!!!

It will give one false signal on the first start of the EA

This is the right and reliable way to do it :

An unnecessary if to the EA is like a rock on the neck.
 
Anton Tarasov:
How to prescribe that with the opening of a candle an order was opened, and with the opening of the next candle it was closed and a new one was opened!
If the time of opening of a bar of the order is less than Time[0], then we close it. If there are no orders after that, we open a new one.
 
Dmitry Fedoseev:
An unnecessary if is like a rock on the neck of the EA.
Put a second else then
 
bool NEW_BAR() еще короче
 {
  static int nBars=0;
  if(nBars!=Bars)
   {
    nBars=Bars;
    return(true);
   }
  return(false);
 }
 
Alexey Busygin:
Put the second one down then.
And that's the same as the dick.
Reason: