I think your error handling is flawed and may be why you think there is no error when actually there is . . .
if(GetLastError()==131) // this reads the error and clears it to 0 Alert("OrderSend failed: Invalid trade volume ("+volume+")"); if(GetLastError()==130) // the error has been cleared this cannot be true Alert("OrderSend failed: Invalid stops ("+StopLoss+")"); if(GetLastError()==4109) // the error has been cleared this cannot be true Alert("OrderSend failed: Please Allow Live Trading!"); Print("OrderSend failed with error #",GetLastError()); // the error has been cleared return(0);
GetLastError() documentation says . . . "The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized"
Also . . . don't use Bars, it isn't reliable as it stops incrementing when you have reached Max bars on chart use time instead.
I think your error handling is flawed and may be why you think there is no error when actually there is . . .
GetLastError() documentation says . . . "The function returns the last occurred error, then the value of special last_error variable where the last error code is stored will be zeroized"
Also . . . don't use Bars, it isn't reliable as it stops incrementing when you have reached Max bars on chart use time instead.
Thanks for your hints. The problem seems to be at the point where I want to select the appropriate order
for(int iPos = 0; iPos < total ; iPos++){ if(OrderSelect(iPos, SELECT_BY_POS) && OrderMagicNumber()==magicNumber && OrderSymbol()==symbol){I've checked the return values from OrderSelect(iPos,SELECT_BY_POS) again and it is always true. So it seems that it can't find an order with the corresponding magicNumber and symbol..?
I think your "if" finds an order, that is not matching to the condition, therefore stops the entire script.
It's actually not entering into the if brackets. So it doesn't find any matching orders.
That is i'am talking about. It enters immediately into the else brackets, and stops. Not because there is no order matching, but there is an order earlier in the list that is not matching.
That is i'am talking about. It enters immediately into the else brackets, and stops. Not because there is no order matching, but there is an order earlier in the list that is not matching.
Just re-thought your suggestion. You are absolutly right. the return(0); in the else clause is wrong. Thank you very much! Stupid mistake ...
That is i'am talking about. It enters immediately into the else brackets, and stops. Not because there is no order matching, but there is an order earlier in the list that is not matching.
Top marks for spotting the actual error!
Unless the required order is first in the list the faulty logic will stop the execution.
Yes, it is easier to me than english :))) thanks!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi @all,
it's me again and I still have questions. sorry :( So here is a simple script that opens an order for me and maintains it. THe script works as supposed but when I'm running the script simultaneously on two different pairs it fails to find one of the orders given its magic number and symbol.
I've manually checked if the magicNumber is unique (which is the case - its the hash function posted here in the forum) but somehow it fails to find the order (OrderSelect has no errors). Help is very muich appreciated. Cheers.
PS: Sorry for the bad code. There are a few dead vars and sometime no error handling..its still under construction :)