open order at new bar only - page 2

 

I found the best function to trade on new bar.

here is the link https://stackoverflow.com/questions/49778099/mql4-listenting-to-candle-bar-open-event

datetime ArrayTime[], LastTime;

void OnTick()
  {
   if(NewBar(_Period))
     {
        your conditions here
     }
//+------------------------------------------------------------------+
bool NewBar(int period)
  {
   bool firstRun = false, newBar = false;
   ArraySetAsSeries(ArrayTime, true);
   CopyTime(Symbol(), period, 0, 2, ArrayTime);
   if(LastTime == 0)
      firstRun = true;
   if(ArrayTime[0] > LastTime)
     {
      if(firstRun == false)
         newBar = true;
      LastTime = ArrayTime[0];
     }
   return newBar;
  }

MQL4 Listenting to Candle Bar Open event
MQL4 Listenting to Candle Bar Open event
  • 2018.04.11
  • CozyAzure CozyAzure 7,520 6 6 gold badges 31 31 silver badges 47 47 bronze badges
  • stackoverflow.com
I am really new to MQL4, and still trying to grasp the concept. I would want to have an event handler to detect every candle bar opening (or every previous candle bar closing). Trying to wrap that around my head but it is not working: So I have a function to check for the tick: where...