Error number 6 - page 5

 
Now i looked through terminal - i got some problems yesterday. <br / translate="no">.
2005.08.11 11:15:00 ****l EURUSD,H1: OrderSend failed with error #139
2005.08.11 11:07:12 TradeDispatcher: all trade context is busy

I have unplugged this EA and will see what happens next.


Here it is. This is it. Here we go. 139 is locked. By whom, why - it's not clear. Then there will be 2, 6, and so on.

What is the most disappointing, there is nothing in this EA that sets it apart from others. So, either I cannot see this "something", or any Expert Advisor may be glitchy, it just may not trigger every hour and, therefore, not everyone has noticed it.

Consequently, my question to everyone - do you have such entries in your logs?

Rosh, do you use Alpari? If so, a question for Alpari - is your server working properly?

What I found out tonight :(

1. The Expert Advisor works by itself, ONE, and either does not give errors or gives them so rarely that overnight is not enough for that.

2. In combination with several other Expert Advisors (more precisely, with one, for six currencies), the error was reproduced, though not in an hour, but in 4 hours.

What follows from this?
1. There is some bug in MT (or in my Expert Advisor, but it is so simple that it is unlikely), which sometimes does not allow me to open trades. And close them too, by the way.
Of course, you can bypass it:

while(nResult == -1) { nResult = OrderSend(...); }



I don't have to tell you that this is a VERY bad programming style and it may offend the broker...

2. I have now rewritten the Expert Advisor to make it simpler, while at the same time causing an error. I will post it in the next few hours. If it appears the error will require two Expert Advisors, what can I do, I will post two :)






 
2. I'm currently rewriting the Expert Advisor to make it simpler, and at the same time to cause an error. I will post it in the next few hours. If it turns out that the error requires two Expert Advisors, what can you do, I will post two :)<br / translate="no">

and we will check
 
Quark, I've made a diagnosis, it's your EA's fault. As soon as Alert comes out of your EA (I don't use them at all) - I immediately get
2005.08.11 13:01:19 TradeDispatcher: all trade context is busy


Alert and blocking times are the same . I haven't looked at the EA code at all.

 
Well. Here's the new superexpert, who is single-handedly producing errors. So far I haven't progressed beyond error 139, so I'll keep testing.

How to use it: for each currency (EURUSD, EURJPY, USDCHF, GBPUSD, GBPJPY,
GBPCHF, USDJPY, AUDUSD, EURGBP, USDCAD, EURCHF, EURAUD) open an hourly chart.
Each chart has an Expert Advisor. They do not interact, as they all have different charts.

Positions will be opened right away, one per chart. At the beginning of the next hour, the positions will have to be reversed, and so on.

I have had 2 errors pop up at a time, so in principle it is possible to have to wait for 2 hours.

If you have a special relationship with the trading server, it's probably better to use a regular account for the test. I use Alpari.

Also note (I assume this is an independent bug) the position of the position opening arrows. In theory, since the position opens on a new bar, the arrow should be on the same bar.

Finally, if you do not want to wait an hour, open the minute charts. The error is reproducible.

Once again, we are talking about error 139. At the same time, I haven't managed to get error 2 and 6 with this method yet. And they have mostly been before. So I guess there will be more posts.

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;

	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 = 0; nCnt < OrdersTotal(); 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);
			}
		}
	}

	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(nError);
	}
}
// ------
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(nError);
	}
}
// ------

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);
}

// ------
 
Quark, I've made a diagnosis, it's your EA's fault. As soon as Alert comes out of your EA (I don't use them at all) - I get <br/ translate="no">
2005.08.11 13:01:19 TradeDispatcher: all trade context is busy


Alert and blocking times are the same . I haven't looked at the EA code at all.



That would be fine, but I introduced alerts after noticing that trades aren't being executed. Also, the alert is in the code right after OrderSend.

Now I'm going to try switching to Print, but I doubt it...
 
By the way, this is interesting. When recompiling an EA, the variable I use to calculate bIsBarEnd is reset. Accordingly, if I press F5 in the editor, all EAs should close old positions and open new ones. I pressed F5. There are 12 currencies (and Expert Advisors). There are 3 updated. Hm?

Put Print instead of Alert to check Rosh's assumption. Alas, the whole difference is that error message 139 now appears in the log and not on the screen.
 
I do not know, I looked at the code; there is nothing to find fault with. I would use Bars to decide this place, not the time of opening.
	The bool bIsBarEnd = false; if(timePrev != Time[0]) bIsBarEnd = true; timePrev = Time[0];



And the thing is not clear:
2005.08.11 13:08:12 '18708' : close order #680413 buy 0.10 EURUSD at 1.2385 sl: 0.0000 tp: 0.0000 at price 1.2408
and then

2005.08.11 13:08:13 '18708': order #680413 buy 0.10 EURUSD at 1.2385 sl: 1.2275 tp: 0.0000 closed at price 1.2408

In other words, at first the order goes without any stops and takeprofit, and then suddenly a stop loss appears in the order

 
I do not know, I looked at the code; there is nothing to find fault with. I would decide about this place through Bars, not by time of opening<br / translate="no">
bool bIsBarEnd = false; if(timePrev != Time[0]) bIsBarEnd = true; timePrev = Time[0]
;



And the thing is not clear:
2005.08.11 13:08:12 '18708' : close order #680413 buy 0.10 EURUSD at 1.2385 sl: 0.0000 tp: 0.0000 at price 1.2408
and then

2005.08.11 13:08:13 '18708': order #680413 buy 0.10 EURUSD at 1.2385 sl: 1.2275 tp: 0.0000 closed at price 1.2408

In other words, at first the order goes without any stops and takeprofit, and then suddenly a stop loss appears in the order



If you have a tested piece of code, I'd love to see "via Bars" :)

As for the zero stop - I've assigned it in init, and I don't change it anywhere else. Bug, I guess. Man, ever since I abandoned C++ I didn't think I'd have to do entomology again.

In fact, well an expert, alright. But it's so simple, that a question arises: isn't there a danger that other EAs would behave the same way? Considering that the bug only appears when there are a lot of Expert Advisors, and it produces different errors.

For example, I have an Expert Advisor using MACD + ADX + Stochastic. Having tested it with a tester (where there are no server errors by definition), will the programmer just sit and check the question "all conditions are fulfilled here but the trade is not closed"? Probably won't... Dangerous bug.
 
<br / translate="no">
If you have a tested piece of code, I'd love to see "via Bars" :)



For example, like this:
int start() { int total,ticket,totalExpert; //---- SetTrace(); if (Bars>b) { b=Bars;
 
Not bad, but essentially the same thing :)
What is SetTrace?