Error number 6 - page 7

 
<br / translate="no"> That's the way to live, and what you're doing is testing the strength of iron.


See the post about the new version of the EA. The iron is now given one second per expert. It didn't get any better.
Then, we were promised that the requests are queued up.
 
Of course, the second variant is correct, but instead of return one should use Sleep() for 30 seconds and that's it.


Here is the variant proposed by Rosh. The errors remain.

double dStopLoss;
int nHoursToHold;

datetime timePrev = 0;

int nSlip = 5;

double dLotSize = 0.1;

int nMagic = 0;

//////////////////
int init ()
{
	timePrev = 0;

	dStopLoss = 110 * Point;
	nHoursToHold = 1;
	
	if(Symbol() == "EURUSD")
		nMagic = 1;
	else if(Symbol() == "EURJPY")
		nMagic = 2;
	else if(Symbol() == "USDCHF")
		nMagic = 3;
	else if(Symbol() == "GBPUSD")
		nMagic = 4;
	else if(Symbol() == "GBPJPY")
		nMagic = 5;
	else if(Symbol() == "GBPCHF")
		nMagic = 6;
	else if(Symbol() == "USDJPY")
		nMagic = 7;
	else if(Symbol() == "AUDUSD")
		nMagic = 8;
	else if(Symbol() == "EURGBP")
		nMagic = 9;
	else if(Symbol() == "USDCAD")
		nMagic = 10;
	else if(Symbol() == "EURCHF")
		nMagic = 11;
	else if(Symbol() == "EURAUD")
		nMagic = 12;
		
//	timePrev += nMagic;	// Open nMagic seconds after the new bar

	return(0);	
}

// ------

int deinit()
{
	return(0);
}
// ------
int start()
{
	if(Bars < 5)
		return(0);
	
	// The previous bar just closed
	bool bIsBarEnd = false;
	if(timePrev != Time[0]) 
		bIsBarEnd = true;
	timePrev = Time[0];
	
	if(!bIsBarEnd)
		return(0);

	// ------
	
	int nSignal = GetSignal();

	if(nSignal == OP_BUY) 
		Buy();
	else if(nSignal == OP_SELL) 
		Sell();

	for(int nCnt = OrdersTotal() - 1; nCnt >= 0; nCnt--)
	{
		OrderSelect(nCnt, SELECT_BY_POS, MODE_TRADES);

		if(OrderMagicNumber() == nMagic)
		{
			if(CurTime() - OrderOpenTime() > (nHoursToHold - 1) * 60 * 60)
			{
				if(OrderType() == OP_BUY)
					OrderClose(OrderTicket(), OrderLots(), Bid, nSlip, Aqua);
				else if(OrderType() == OP_SELL)
					OrderClose(OrderTicket(), OrderLots(), Ask, nSlip, OrangeRed);
					
				Sleep(10);
			}
		}
	}

	return(0);
}
// ------

void Sell()
{
	if(AccountFreeMargin() < 500)
		return;

	dLotSize = GetLotSize();

	int nResult = OrderSend(Symbol(), OP_SELL, dLotSize, Bid, nSlip, Bid + dStopLoss, 
		0, "Friday", nMagic, 0, OrangeRed);

	if(nResult == -1)
	{
		int nError = GetLastError();
		Alert(Symbol() + ", " + nError);
	}

Sleep(10);
}
// ------
void Buy()
{
	if(AccountFreeMargin() < 500)
		return;

	dLotSize = GetLotSize();

	int nResult = OrderSend(Symbol(), OP_BUY, dLotSize, Ask, nSlip, Ask - dStopLoss, 
		0, "Friday", nMagic, 0, Aqua);

	if(nResult == -1)
	{
		int nError = GetLastError();
		Alert(Symbol() + ", " + nError);
	}

Sleep(10);
}
// ------

double GetLotSize()
{
	double dLot = 0.1;
	
	return(dLot);
}

// ------

int GetSignal()
{
	int nSignal;
	if(MathMod(Hour(), 2) == 0)
		nSignal = OP_BUY;
	else
		nSignal = OP_SELL;
		
	return(nSignal);
}

// ------



 
This point
if(OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, nSlip, Aqua); else if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, nSlip, OrangeRed)
;


what is the OrderType() if we closed the buy order (the first condition was met)
Try to drop the check in the second condition, i.e. I always write it like this:

if(OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, nSlip, Aqua); if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, nSlip, OrangeRed);
 
Well, as always, Rosh seems to be right. I set Sleep(0), two experts already give errors. I put Sleep(100), four experts work, errors appear when adding the fifth (five windows, five currencies, one expert for each).

I set Sleep(200) - five experts get on (almost, sometimes they still give errors. I have not managed to get 5 Expert Advisors without errors using this method).

For now, I am speaking only about errors 138 and 139.

Still waiting for some tips from developers.

Rosh, special thanks to you, although I don't like your approach with slip.
 
Such a moment<br / translate="no">
if(OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, nSlip, Aqua); else if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, nSlip, OrangeRed)
;


What is OrderType() if we have closed a buy order (the first condition has been met)
Try to drop the check in the second condition, i.e. I always write it this way:

if(OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, nSlip, Aqua); if(OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, nSlip, OrangeRed);



Yes, probably. Though I put a pause after this if, but who knows them, multitaskers.

Tried it. I feel better, but I still have errors :)
 
<br / translate="no">
Rosh, special thanks to you, although I don't like your approach with the slip.


Well... life isn't the best I've seen either. There's such a thing as dying at some point. I don't like it either, but the Developer doesn't change the version. :)
 


Rosh, тебе отдельное спасибо, хотя твой подход со слипом мне не нравится.


Well... life isn't the best thing I've ever seen, either. There is such a thing as dying at some point. I don't like it either, but the Developer doesn't change the version. :)


Yeah, and the API doesn't put out :)
But you can always find a workaround :)) Using Sleep(), for example :)))

But in general, this is a profound remark. You should apply to developers more often. They say they sometimes answer :))))
 
Can I have a chat with you guys? =)))
Because you have such a discussion for 4 pages, and I'm silent (drinking day =))...


About the errors:
Error #6 - no connection with trade server - may be due to bad connection. I have a Data Over Voice leased line, and when you pick up the phone, the speed drops dramatically. So it's precisely at these moments that this error occurs.

Error #139 - order is locked - I think it's just a glitch: like terminal does something with this position and EA cannot work with it at that moment. I don't know, I cannot find any other explanation (

Error #138 - requote - it may be caused by connection too. Look at channel load during errors.

All this is pure speculation, though. I asked the developers for a long time for a normal description of errors and instructions on how to react - they said they would come one day ;)



Regarding Sleep() - it's always silly to use it. But it's better to make pause between trades - use LastTradeTime. I am finishing (remaking) the trade_lib&info_lib.mqh library. All these questions are solved there (partially). There should be much fewer errors.


That's all my thoughts so far, if I think of anything else - I'll tell ;)
 
<br/ translate="no"> Can I have a chat with you guys? =)))
You've got a four-page discussion, and I'm silent (drinking day =))...


Yes, I've made a lot of noise... :)


About the errors:
Error #6 - no connection with trade server - may be due to bad connection. I have a Data Over Voice leased line, and when you pick up the phone, the speed drops dramatically. So it's precisely at these moments that this error occurs.


I got a leased line, good quality. Again, a bad connection does not explain why an error occurs EVERY time several EAs do something simultaneously. With a megabit (in theory) channel!


Error #139 - order is locked - it seems to me that it's just a glitch: like the terminal does something with this position and Expert Advisor cannot work with it at that moment. I do not know, I cannot find any other explanation (


Agreed. There's just a trifle left to figure out WHERE he's doing it. The expert is so simple that there is simply no such place. Although, of course, maybe it's me who can't see it. (do you see a moose? no. and I don't. but he is NOW)


Error #138 - requote may well be due to connection. Check link load during errors.


I don't know. If you can't trade two EAs at the same time in Moscow on a leased line, you can't trade at all.

I was thinking about requotes. For example, what is the minimum slip one has to put to keep the price from running away. 5 points? 10? I set 15 - the error stays.


All this is pure speculation, though. I asked the developers for a long time for a normal description of errors and instructions on how to react - they said they would come one day ;)


And they say the market is perfect! Ha!


Regarding Sleep() - it's always silly to use it. But it would be better to make a pause between trades - use LastTradeTime. I am finishing (remaking) the trade_lib&info_lib.mqh library - I will post it on the wiki and give you the link. All these questions are solved there (partially). There should be much less errors.


I already wrote that these errors can be bypassed "directly" - by sending OrderSend in a loop, until it returns a value other than minus 1. But the question is of principle - what happens? I get errors of 5-6 different types at once. If I draw a workaround for today, they will pop up tomorrow where they are not expected. If I trade on demo, I'd better solve this issue. I will have losses later.


That's all my thoughts for now, if I think of anything else, I will tell you ;)


Thanks :)
Try to run this Expert Advisor on your EA. Maybe you'll get some ideas. Or - if you trade on a demo - put similar alerts in your EAs... who knows... what if they don't open all deals?
 
I get errors like that all the time too. And I sit in Alpari too. Maybe you should try another brokerage company? Maybe it's not MT's fault?