Sending orders based on new candle data as opposed to new tick generation

 
Hi guys am new here (to the forum & to coding)

Am trying to code a strategy that executes positions based on candle data collected at the close of each candle, the problem I have is that the ontick function completely messes up the strategy because each time a new tick is released the strategy calculates and sends orders based on incomplete information 


I'd like to know if there's a way to run the strategy at the close of each candle rather than each time a new tick is generated. 

If anyone knows of a method or a way that can help or bring me closer to what I need please help


Thank you 
 
void OnTick()
  {
if (isNewBar())

and then add this to the bottom of EA. It's messy but it'll do what you want


bool isNewBar()
  {
//--- memorize the time of opening of the last bar in the static variable
   static datetime last_time=0;
//--- current time
   datetime lastbar_time=SeriesInfoInteger(Symbol(),Period(),SERIES_LASTBAR_DATE);
//--- if it is the first call of the function
   if(last_time==0)
     {
      //--- set the time and exit
      last_time=lastbar_time;
      return(false);
     }

//--- if the time differs
   if(last_time!=lastbar_time)
     {
      //--- memorize the time and return true
      last_time=lastbar_time;
      return(true);
     }
//--- if we passed to this line, then the bar is not new; return false
   return(false);
  }
 
oneflewoverthecuckoosnest #:

and then add this to the bottom of EA. It's messy but it'll do what you want


Thank you it works perfectly 
 
Noted