Thread: How to code?
View Single Post
  #1497 (permalink)  
Old 12-11-2008, 01:59 PM
litcons litcons is offline
Junior Member
 
Join Date: Feb 2008
Posts: 10
litcons is on a distinguished road
Hello, I have an expert i use that needs to be able to resend a buy or a sell order if there is a problem opening the order up if the the server is disconnected, busy or what have you. This morning it should have opened an order but couldn't because the platform was disconnected. In the code right now it is set to wait 3 seconds then try again, which it did but it only tried 3 times then stopped trying to send the order thru. my ea doesn't scalp but is more a mid term trade so I only get 1-3 trades per week per pair. How can i have it coded so it will wait 10 seconds before it tries again and then it will keep trying to send the order until it gets through, i would like to have the option of adjusting it in the code how many seconds it waits to try again and then also how many times it will keep trying.

I've attached a snippet of code so someone could see what could be changed. Thanks in advance for your help!

Mike

RefreshRates();
int ticket=OrderSend(Symbol(),OP_BUY,ManagedLotSize(), Ask,Slippage,sl,tp,"Expert" + " - " + Period(),MagicNumber,0,Lime);

if(ticket<0)
{
Print("Error opening BUY order : ",GetLastError());

Sleep(3000); //---- wait for 3 seconds
}
else
{
break;
}
}
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
{
Print("BUY order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening BUY order : ",GetLastError());
}
}

void ManageSell()
{
double tp,sl;
if (TakeProfit==0) { tp=0; } else { tp=Bid-TakeProfit*Point; }
if (StopLoss==0) { sl=0; } else { sl=Bid+StopLoss*Point; }

for (int i = 1; i <=5; i++) //---- Loop if requote
{
RefreshRates();
int ticket=OrderSend(Symbol(),OP_SELL,ManagedLotSize() ,Bid,Slippage,sl,tp,"Expert" + " - " + Period(),MagicNumber,0,Red);

if(ticket<0)
{
Print("Error opening SELL order : ",GetLastError());

Sleep(3000); //---- wait for 3 seconds
}
else
{
break;
}
}
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES ))
{
Print("SELL order opened : ",OrderOpenPrice());
}
else
{
Print("Error opening SELL order : ",GetLastError());
}
Reply With Quote