MT4: How to limit to one buy/sell order per bar?

 
I have the problem that my Expert Advisor keeps firing multiple orders during a bar. I tried to limit the orders to the beginning of the bar by using:

...
datetime prevtime=0;
...

if(Time[0] > prevtime)
{
//execute my OrderSend function
}
...
prevtime = Time[0];
...

shouldn't this recognize the beginning of a bar? When I use the strategy tester, absolutely nothing happens and this does not seem to work.

Any help most appreciated.
 
static datetime ordertime=0;  // or define globally outside the start() function
somelimit= 15; // 15 minutes (e.g. on a 15M chart)
...

if((Time[0]-ordertime)>somelimit*60)  
{
  //execute my OrderSend function
  ordertime = Time[0];
}
...

 
//declare this variable or something like it
double    barcheck;

//have one of your conditions for opening an order be
if(Bars > barcheck)


//then, when you open an order, place this script
barcheck  =  Bars;



 
static datetime ordertime=0;  // or define globally outside the start() function



hello Shimodax and mcboogs,

thank you for your ideas. i think my main problem was that i did not define my prevtime variable as 'static' (thx for this, Shimodax). it seems to work now. the manual says that bar distinction on time is more reliable than on count of bars, because the bar count may not work for the strategy tester.

:)
Reason: