You are correct, the return (false) skips the retry logic within SendSingleTrade() (and should be fixed), but outside of that loop in LookForTradingOpportunities(), if SendSingleTrade() returns false, it resets the bar count and tries again on the next tick.SteveM wrote:I'm new to Empty4 and a long time since I coded so I could very easily be way offSteveHopwood wrote: The code should force the ea to keep trying to send the trade. Anyone spotting a flaw here, please sing out.
This is in the send single trade function, inside a for(;;) loopWon't the "return (false)" part exit the function completely rather than go through the loop again?Code: Select all
Print(Symbol(), " ", WindowExpertName(), " ", stype," order send failed with error(",err,"): ",ErrorDescription(err)); return(false);
We should probably differentiate between temporary and permanent errors and only retry on temporary ones.
From stderror.mqh:
Code: Select all
#define ERR_NO_ERROR 0
#define ERR_NO_RESULT 1
#define ERR_COMMON_ERROR 2
#define ERR_INVALID_TRADE_PARAMETERS 3
#define ERR_SERVER_BUSY 4
#define ERR_OLD_VERSION 5
#define ERR_NO_CONNECTION 6
#define ERR_NOT_ENOUGH_RIGHTS 7
#define ERR_TOO_FREQUENT_REQUESTS 8
#define ERR_MALFUNCTIONAL_TRADE 9
#define ERR_ACCOUNT_DISABLED 64
#define ERR_INVALID_ACCOUNT 65
#define ERR_TRADE_TIMEOUT 128
#define ERR_INVALID_PRICE 129
#define ERR_INVALID_STOPS 130
#define ERR_INVALID_TRADE_VOLUME 131
#define ERR_MARKET_CLOSED 132
#define ERR_TRADE_DISABLED 133
#define ERR_NOT_ENOUGH_MONEY 134
#define ERR_PRICE_CHANGED 135
#define ERR_OFF_QUOTES 136
#define ERR_BROKER_BUSY 137
#define ERR_REQUOTE 138
#define ERR_ORDER_LOCKED 139
#define ERR_LONG_POSITIONS_ONLY_ALLOWED 140
#define ERR_TOO_MANY_REQUESTS 141
#define ERR_TRADE_MODIFY_DENIED 145
#define ERR_TRADE_CONTEXT_BUSY 146
#define ERR_TRADE_EXPIRATION_DENIED 147
#define ERR_TRADE_TOO_MANY_ORDERS 148
#define ERR_TRADE_HEDGE_PROHIBITED 149
#define ERR_TRADE_PROHIBITED_BY_FIFO 150
Code: Select all
#define ERR_COMMON_ERROR 2
#define ERR_INVALID_TRADE_PARAMETERS 3
#define ERR_OLD_VERSION 5
#define ERR_NO_CONNECTION 6
#define ERR_NOT_ENOUGH_RIGHTS 7
#define ERR_TOO_FREQUENT_REQUESTS 8
#define ERR_MALFUNCTIONAL_TRADE 9
#define ERR_ACCOUNT_DISABLED 64
#define ERR_INVALID_ACCOUNT 65
#define ERR_INVALID_TRADE_VOLUME 131
#define ERR_MARKET_CLOSED 132
#define ERR_TRADE_DISABLED 133
#define ERR_NOT_ENOUGH_MONEY 134
#define ERR_ORDER_LOCKED 139
#define ERR_LONG_POSITIONS_ONLY_ALLOWED 140
#define ERR_TOO_MANY_REQUESTS 141
#define ERR_TRADE_MODIFY_DENIED 145
#define ERR_TRADE_EXPIRATION_DENIED 147
#define ERR_TRADE_TOO_MANY_ORDERS 148
#define ERR_TRADE_HEDGE_PROHIBITED 149
#define ERR_TRADE_PROHIBITED_BY_FIFO 150
Code: Select all
#define ERR_INVALID_PRICE 129
#define ERR_INVALID_STOPS 130
#define ERR_PRICE_CHANGED 135
#define ERR_OFF_QUOTES 136
#define ERR_BROKER_BUSY 137
#define ERR_REQUOTE 138
#define ERR_TRADE_CONTEXT_BUSY 146
Code: Select all
//check for temporary errors
if (err != ERR_NO_ERROR &&
err != ERR_NO_RESULT &&
err != ERR_INVALID_STOPS &&
err != ERR_PRICE_CHANGED &&
err != ERR_OFF_QUOTES &&
err != ERR_BROKER_BUSY &&
err != ERR_REQUOTE &&
err != ERR_TRADE_CONTEXT_BUSY)
return(false);
George