ERR_NO_CONNECTION coming up from time to time!?

 

When I OrderSend() every minute, I tend to get about one ERR_NO_CONNECTION per hour. This is on a VPS (I'm also assuming the broker is reliable). After the failure, the trade always goes through successfully when I retry immediately. I am beginning to suspect that there is something more at play here than a proper failed connection.

Has anyone else had issues here with somewhat frequent ERR_NO_CONNECTION on a VPS when the problem is really something else?


If it is useful, below is my code used to open a new trade -

// Make the open trade
bool ChangePositionSizeOpen(double openLots, int logHandle, double slippagePoints, int magicNumber)
{
bool openSuccess = true;
double lotsOpened = 0;

// Step through the active tickets and close them, each time adding to lotsClosed
openLots = NormalizeDouble(openLots, MIN_CONTRACT_PRECISION);
if (openLots != 0)
{
// Try opening and repeat on failure
int failureCount = 0;
double originalPrice = 0; // The price when first trade is attempted
double price = 0;
int cmd = -1;
while (failureCount < MAX_TRADE_TRIES)
{
// Set the price, originalPrice and cmd
RefreshRates();
if (openLots > 0)
{
price = Ask;
cmd = OP_BUY;
}
else
{
price = Bid;
cmd = OP_SELL;
}
if (failureCount == 0)
originalPrice = price;

// Create the open order
int ticket = OrderSend(Symbol(), cmd, MathAbs(openLots), price, slippagePoints, 0, 0, WindowExpertName(), magicNumber);
if(ticket > 0)
{
// Success
if (OrderSelect(ticket, SELECT_BY_TICKET) == true)
LogMessage(logHandle, "OPEN SUCCESS: Ticket=", ticket, ", LotsAttempted=", openLots, ", LotsAct=", OrderLots(), ", PriceOrg=", DoubleToStr(originalPrice,6), ", Price=", DoubleToStr(price,6), ", PriceAct=", DoubleToStr(OrderOpenPrice(),6));
else
Alert("Failure to find ticket=", ticket);

lotsOpened = openLots;
break;
}
else
{
// Failure
int lastError = GetLastError();
Alert("OPEN ERROR=", lastError, ", lots=", openLots, ", price=", DoubleToStr(price,6));
LogMessage(logHandle, "OPEN ERROR=", lastError, ", lots=", openLots, ", price=", DoubleToStr(price,6));

failureCount += 1;
if (failureCount > MAX_IMMEDIATE_TRADE_RETRIES)
Sleep(5000);
}
}
}

// Report the success of closing trades
openSuccess = openSuccess && NormalizeDouble(lotsOpened,MIN_CONTRACT_PRECISION) == NormalizeDouble(openLots,MIN_CONTRACT_PRECISION);
return(openSuccess);
}

 
Has anyone else had issues here with somewhat frequent ERR_NO_CONNECTION on a VPS when the problem is really something else? Not me. Usually changing brokers or choosing closer vps solves the problem.
 
Thanks Ubzen. I guess it may actually be what it says - a failed connection. It is odd though that it is only a split second every so often rather than extended period.
 
Not odd at all. It takes the terminal about a minute to timeout and attempt to reconnect. Since you're trading every minute, you're seeing every little glitch.
Reason: