This is a very specific MT4 coding question regarding live error checking and also testing.
The two code examples below are the same except one example uses (!buyticket) instead of (buyticket<0)
The code with if (buyticket<0) is used on OrderSend and is on a live account and working well and quickly executes opening buy/sell orders without a problem.
However in testing mode it hangs the tester and stops testing after only a few passes and 4 or 5 seconds with a message saying all other passes were insignificant. But if the OrderSend code is checked with (!buyticket) instead of (buyticket<0), it tests all available passes.
My understanding is that OrderSend returns the ticket number or -1, so the (buyticket<0) is used, but the tester hangs with this code. So I alter it during tests with if (!buyticket) which is normally the error checking code for OrderModify which returns false if there is an error, which is boolean thus (!buyticket). But OrderSend does not return a boolean value.
Can someone explain why the tester hangs with if (sellticket<0) ?
Code normally used in live EA mode...
Code altered for testing mode only...
Incidentally, I used the 2nd example of if (!sellticket) on live trading and sometimes the second order, the sell order doesn't get executed and doesn't produce the error message either, but with the standard if (sellticket<0) it works fine. My confusion and question is why does the tester not like if (sellticket<0) when testing?
The two code examples below are the same except one example uses (!buyticket) instead of (buyticket<0)
The code with if (buyticket<0) is used on OrderSend and is on a live account and working well and quickly executes opening buy/sell orders without a problem.
However in testing mode it hangs the tester and stops testing after only a few passes and 4 or 5 seconds with a message saying all other passes were insignificant. But if the OrderSend code is checked with (!buyticket) instead of (buyticket<0), it tests all available passes.
My understanding is that OrderSend returns the ticket number or -1, so the (buyticket<0) is used, but the tester hangs with this code. So I alter it during tests with if (!buyticket) which is normally the error checking code for OrderModify which returns false if there is an error, which is boolean thus (!buyticket). But OrderSend does not return a boolean value.
Can someone explain why the tester hangs with if (sellticket<0) ?
Code normally used in live EA mode...
Inserted Code
void MarketBuy() { buyticket = OrderSend(EASymbolTrendAgg101NAS,OP_BUY,LotsOptimized(),Ask,Slip,0,0,"",0,0,Blue); if (buyticket<0) {MarketBuy(); Print (">>> BUY ORDER NOT EXECUTED !!! OPENING BUY ORDER RE-SUBMITTED >>>");} else MarketSell();} void MarketSell() { sellticket = OrderSend(EASymbolTrendAgg101NAS,OP_SELL,LotsOptimized(),Bid,Slip,0,0,"",0,Red); if (sellticket<0) {MarketSell(); Print (">>> SELL ORDER NOT EXECUTED !!! OPENING SELL ORDER RE-SUBMITTED >>>");} else ConfirmSLTP(); return;}
Code altered for testing mode only...
Inserted Code
void MarketBuy() { buyticket = OrderSend(EASymbolTrendAgg101NAS,OP_BUY,LotsOptimized(),Ask,Slip,0,0,"",0,0,Blue); if (!buyticket) {MarketBuy(); Print (">>> BUY ORDER NOT EXECUTED !!! OPENING BUY ORDER RE-SUBMITTED >>>");} else MarketSell();} void MarketSell() { sellticket = OrderSend(EASymbolTrendAgg101NAS,OP_SELL,LotsOptimized(),Bid,Slip,0,0,"",0,Red); if (!sellticket) {MarketSell(); Print (">>> SELL ORDER NOT EXECUTED !!! OPENING SELL ORDER RE-SUBMITTED >>>");} else ConfirmSLTP(); return;}
Incidentally, I used the 2nd example of if (!sellticket) on live trading and sometimes the second order, the sell order doesn't get executed and doesn't produce the error message either, but with the standard if (sellticket<0) it works fine. My confusion and question is why does the tester not like if (sellticket<0) when testing?