avoid multiple trading at the same time.

 

Hi, greetings.

i'm trying to avoid trading at the same time and written the following codes by referring to forums.

can anyone advice me whats went wrong?

///////////////////////////////////////////////////////////////////////////////////////

if (TimeMinute(TimeCurrent())>= Timedelay)
{
Timedelay = 0;
ticket=OrderSend(Symbol(),OP_SELL,lotMM,Bid,3,0,Bid-TakeProfit*Point,"Sample Code",MagicNumber,0,Red);
//---- wait for 3 seconds
Sleep(3000);
Timedelay = TimeMinute(TimeCurrent())+15;
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}

///////////////////////////////////////////////////////////////////////////////////////

 

Is your "Timedelay" a "static int"? Or it'll be zero every new run time.

Declare like this:

static int Timedelay;

 
zilin:

Is your "Timedelay" a "static int"? Or it'll be zero every new run time.

Declare like this:

static int Timedelay;

thanks it works by defining "static int Timedelay;"!!! but there is another problem.

for the function :-

if (TimeMinute(TimeCurrent())>= Timedelay)

lat say the first trade was taken at 1:59.... then the next possible entry is 2:15; by referring to above function, it will not accept any trades unless "Timedelay" is set to 0.


Leon


 
Leonfoo:

if (TimeMinute(TimeCurrent())>= Timedelay)
{
Timedelay = 0;

static datetime nextAllowed;
if (CurTime() >= nextAllowed) {  
  nextAllowed = CurTime() + 15*60; // 15 minutes
  ... // new order allowed
Must avoid roll over 0 15, 30 45, 0
 
WHRoeder:
Must avoid roll over 0 15, 30 45, 0

Hi WHRoeder.

it works great!! thanks every one for the comment.


current change:-

static datetime Timedelay;

if (CurTime() >= Timedelay)
{
ticket=OrderSend(Symbol(),OP_SELL,lotMM,Bid,3,0,Bid-TakeProfit*Point,"sample",MagicNumber,0,Red);
Sleep(3000); //---- wait for 3 seconds
Timedelay = CurTime() + 15*60; // 15 minutes delay
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL order : ",GetLastError());
return(0);
}

Reason: