It seems a lot of people who had previously hired me to write EAs for them have had those EAs suddenly stop working.
The main problem was they didn't understand the different requirements of an ECN Broker and a Non-ECN Broker. I spent some time trying to figure out how to detect whether or not a broker is an ECN and to have the EA handle that appropriately.
The way the function works is simple enough.
The EA first tries to place a trade normally--assuming the broker is a non-ecn broker. If there are no OrderSend() errors, but no trade is placed or detected, the EA knows that broker is an ECN broker and will act accordingly.
At least, that's what is supposed to happen in a perfect world.
The main problem was they didn't understand the different requirements of an ECN Broker and a Non-ECN Broker. I spent some time trying to figure out how to detect whether or not a broker is an ECN and to have the EA handle that appropriately.
Inserted Code
bool ECNBroker = False; //This variable goes in the global variables section. int SendOrder(string OpenSymbol, int OpenCommand, double OpenVolume, double OpenPrice, int OpenSlippage, double OpenStopLoss, double OpenTakeProfit, string OpenComment, int OpenMagicNumber, datetime OpenExpiration, color OpenColor) { int FTicket = -2; if(!ECNBroker) { FTicket = OrderSend(OpenSymbol, OpenCommand, OpenVolume, OpenPrice, OpenSlippage, OpenStopLoss, OpenTakeProfit, OpenComment, OpenMagicNumber, OpenExpiration, OpenColor); if(FTicket == -1) { return(FTicket); } if(OrderSelect(FTicket, SELECT_BY_TICKET, MODE_TRADES)) { return(FTicket); } else { ECNBroker = True; } } if(ECNBroker) { FTicket = OrderSend(OpenSymbol, OpenCommand, OpenVolume, OpenPrice, OpenSlippage, 0.0, 0.0, OpenComment, OpenMagicNumber, OpenExpiration, OpenColor); if(FTicket > 0) { OrderSelect(FTicket, SELECT_BY_TICKET, MODE_TRADES); OrderModify(FTicket, OrderOpenPrice(), OpenStopLoss, OpenTakeProfit, OrderExpiration(), CLR_NONE); } return(FTicket); } }
The way the function works is simple enough.
The EA first tries to place a trade normally--assuming the broker is a non-ecn broker. If there are no OrderSend() errors, but no trade is placed or detected, the EA knows that broker is an ECN broker and will act accordingly.
At least, that's what is supposed to happen in a perfect world.