Error number 6 - page 11

 
in 50 minutes of work on 10 minute charts only 2 requotes. no more errors. let's add the meta-editor's dictionary and post the changes
 
error 138 requote can easily occur. potentially with 10 working EAs the waiting time for semaphore release can be 30 seconds or more. during this time the price can easily change. in this case use RefreshRates function and take a new bid or ask value. or ask MarketInfo for a new price. 129 is the same error, wrong price - the price has gone too far and there were several price changes during the waiting time. 1 - this is not an error at all. it appears when you are trying to modify an order with the same values you have already set. it is strange that it occurs when you manually confirm a trade when you reject it


Thanks, but...
The last EA I posted has a 3 second lag and 50 (!) pips slippage. Price
12 charts of 3 seconds each - price won't have time to run that far. Or am I misunderstanding something?
 
Added RefreshRates to expert (code below). Errors number 1 are now piling up.
Hopefully you can track it down. "Dropping" means about once every 2-3 minutes. If you don't - probably the server is too close, or there computer is too fast. I have part of my CPU taken up by a neural network packet, so MT gets 50%... Now... Here, disabled the neural network (there's a pause button, unlike some other programs). Error number one hasn't gone away, but has become a little less frequent. MT is "eating" 55-99% of CPU. Turning it on... MT gets 1.5 times less CPU time. Error became more frequent too.

double dStopLoss;
int nHoursToHold;

datetime timePrev = 0;
int nBars;
int nDelaySeconds = 3;

int nSlip = 50;

double dLotSize = 0.1;

int nMagic = 0;
int nDigits;

string strTradeSemaphore = "TradeSemaphore";

//////////////////
int init()
{
	nBars = Bars;

	if(!IsTesting() && !GlobalVariableCheck(strTradeSemaphore)) 
		GlobalVariableSet(strTradeSemaphore, 0.0);
	
	dStopLoss = 110 * Point;
	nHoursToHold = 1;

	nDigits = MarketInfo( Symbol(), MODE_DIGITS );
	
	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] + nMagic) 
		bIsBarEnd = true;
	timePrev = Time[0] + nMagic;
*/

	bool bIsBarEnd = false;
	if(nBars != Bars)
	{
		if(IsTesting() || (!IsTesting() && CurTime() > Time[0] + nMagic * nDelaySeconds))
		{
			bIsBarEnd = true;
			nBars = Bars;
		}
	}
	
	if(!bIsBarEnd)
		return(0);

	// ------
	
	if(!IsTesting())
	{
		while(!IsStopped())
		{
			if(GlobalVariableGet(strTradeSemaphore) == 0.0)
				GlobalVariableSet(strTradeSemaphore, nMagic);

			if(GlobalVariableGet(strTradeSemaphore) == nMagic)
				break;
		
			Sleep(1000);
		}
	}
	
	RefreshRates();
	
	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);
			}
		}
	}

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

	if(!IsTesting())
		GlobalVariableSet(strTradeSemaphore, 0.0);	
	
	return(0);
}
// ------

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

	dLotSize = GetLotSize();

	double dNormalizer = MathPow(10, nDigits);
	double dBid = Bid;//MathFloor(Bid * dNormalizer) / dNormalizer; //NormalizeDouble(Bid, nDigits);
	double dStop = Bid + dStopLoss;//MathFloor((Bid + dStopLoss) * dNormalizer) / dNormalizer; //NormalizeDouble(Bid + dStopLoss, nDigits);

	int nResult = OrderSend(Symbol(), OP_SELL, dLotSize, dBid, 
		nSlip, dStop, 0, "Friday", nMagic, 0, OrangeRed);

	if(nResult == -1)
	{
		int nError = GetLastError();
		Alert(Symbol() + ", sell: " + dBid + ", Stop: " + dStop + ", error: " + nError);
	}
}

// ------

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

	dLotSize = GetLotSize();

	double dNormalizer = MathPow(10, nDigits);
	double dAsk = Ask;//MathFloor(Ask * dNormalizer) / dNormalizer; //NormalizeDouble(Bid, nDigits);
	double dStop = Ask - dStopLoss;//MathFloor((Ask - dStopLoss) * dNormalizer) / dNormalizer; //NormalizeDouble(Bid + dStopLoss, nDigits);

	int nResult = OrderSend(Symbol(), OP_BUY, dLotSize, dAsk, 
		nSlip, dStop, 0, "Friday", nMagic, 0, Aqua);

	if(nResult == -1)
	{
		int nError = GetLastError();
		Alert(Symbol() + ", buy: " + dAsk + 
			", Stop: " + dStop + ", error: " + 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);
}


 
To summarise, I guess. It seems that any expert, except those working all alone, needs protective semaphores. I'll try the new feature introduced by the developers on Monday (and Rosh said the Developer doesn't want to change the version! I should contact him more often, it's only a hundred posts away). Actually, thanks a lot to the developers. Thanks also to Rosh and Composer. However, we'll wait until Monday :)
 
Nah, not until Monday for sure =)))
The South is calling, and the new feature will be promptly tested in a week =)))))

...and thank you too, at least someone tried to work out the bugs ;)
 
To summarise, I guess. It seems that any expert, except those working all alone, needs protective semaphores. I'll try the new feature introduced by the developers on Monday (and Rosh said the Developer doesn't want to change the version! I should contact him more often, it's only a hundred posts away). Actually, thanks a lot to the developers. Thanks also to Rosh and Composer. However, see you on Monday :)<br / translate="no">


Quark, I wrote about the Developer, not the developers. :) Get it? In some religions it's God, in others it's a different address.
Also, I wrote that my 9 EAs work fine on one account. But you're good at finding the conditions when MT4 is shoveling something wrong :)
 
<br / translate="no"> no, not until Monday =)))


See you Monday :)


The South is calling and the new f-function will be promptly tested in a week =)))))


A big hello to the South.


...and thank you too, at least someone tried to work out the bugs ;)


With one mistake. And how many of them...
 
<br / translate="no"> Quark, I wrote about the Developer, not the developers. :)


I was only joking :) Although the principle is the same everywhere. If you ask correctly, you get an answer. If you swear, you get banned :)


And I also wrote that my 9 EAs are running fine on the same account. But you're good at finding the conditions when MT4 is shoveling something wrong :)


72 windows with 12 of my councillors - also. Then I added the 13th, and here we go... In general, of course, if I take the last EA posted in this branch and use it at watches instead of minutes, and increase pause from 3 seconds to 30 (as you suggested, by the way) there won't be errors. So the result is achieved, a positive one...

It's a pity about guys from English forum, but I won't translate our posts for them. Not in good health :(

Good luck,
Quark
 
Despite the work done, error number 6 continues to occur. It happens when MT uses the optimiser and opens a position at the same time. I have already caught it twice. Running the Expert Advisor again - if the conditions for opening a position are still valid - results in opening a position, no problems.
 
It seems that when the optimiser is running, error 6 is much more likely. Restarting the computer, MT etc. measures do not change the situation.

The problem occurs on different EAs. Logic in all of them was modified with semaphores (as Slava suggested) and delay (Rosh) - so that in given 10 seconds only 1 EA was working. All errors I mentioned above disappeared (so far), except number 6.