You are using TRADE_ACTION_PENDING and ORDER_TYPE_BUY, a BUY is not a pending. Check the documentation please.
Hello MQL5 Community.
I am getting this error when I ran my code in demo account. The error is "invalid request",. what is wrong with my code?
void GenerateTradeSignal(double ema5Buffer_0, double ema20Buffer_0, double ema5Buffer_1, double ema20Buffer_1) { if(ema5Buffer_0 > ema20Buffer_0 && ema5Buffer_1 < ema20Buffer_1 && ema5Buffer_0 - ema20Buffer_0 > confirmationThreshold && ema5Buffer_0 - ema20Buffer_0 > priceMovementThreshold) { Print("Buy signal generated: confirmationThreshold = ", confirmationThreshold, ", priceMovementThreshold = ", priceMovementThreshold); // Place buy order at the crossover price double crossoverPriceBuy = SymbolInfoDouble(Symbol(), SYMBOL_ASK); // Get the current ask price MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; request.symbol = Symbol(); request.volume = 0.01; request.price = crossoverPriceBuy; request.deviation = 1; request.type = ORDER_TYPE_BUY; request.type_filling = ORDER_FILLING_FOK; request.magic = 123456; request.comment = "Buy Order"; double stopLossPercentage = 9.0; double stopLossLevel = crossoverPriceBuy - (crossoverPriceBuy * stopLossPercentage / 100.0); request.sl = stopLossLevel; double takeProfitPercentage = 13.0; double takeProfitLevel = crossoverPriceBuy + (crossoverPriceBuy * takeProfitPercentage / 100.0); request.tp = takeProfitLevel; if(OrderSend(request, result)) { if(result.retcode == TRADE_RETCODE_DONE) { Print("Buy order placed successfully"); ApplyTrailingStop(stopLossPercentage); } else { Print("Failed to place buy order. Error:", result.retcode); } } } else if(ema5Buffer_0 < ema20Buffer_0 && ema5Buffer_1 >= ema20Buffer_1 && ema20Buffer_0 - ema5Buffer_0 > confirmationThreshold && ema20Buffer_0 - ema5Buffer_0 > priceMovementThreshold) { Print("Sell signal generated: confirmationThreshold = ", confirmationThreshold, ", priceMovementThreshold = ", priceMovementThreshold); // Place sell order at the crossover price double crossoverPriceSell = iClose(Symbol(), 0, 1); // Get the closing price of the previous candle MqlTradeRequest request; MqlTradeResult result; request.action = TRADE_ACTION_DEAL; request.symbol = Symbol(); request.volume = 0.01; request.price = crossoverPriceSell; request.deviation = 1; request.type = ORDER_TYPE_SELL; request.type_filling = ORDER_FILLING_FOK; request.magic = 123456; request.comment = "Sell Order"; double stopLossPercentage = 9.0; double stopLossLevel = crossoverPriceSell + (crossoverPriceSell * stopLossPercentage / 100.0); request.sl = stopLossLevel; double takeProfitPercentage = 13.0; double takeProfitLevel = crossoverPriceSell - (crossoverPriceSell * takeProfitPercentage / 100.0); request.tp = takeProfitLevel; if(OrderSend(request, result)) { if(result.retcode == TRADE_RETCODE_DONE) { Print("Sell order placed successfully"); ApplyTrailingStop(stopLossPercentage); } else { Print("Failed to place sell order. Error:", result.retcode); } } } else { // No valid crossover or false signal Print("No valid crossover detected or false signal"); } }
Any assistance will be appreciated. Thank you
Francis
Hi, can someone correct me what is the mistake below?
I got error code 10013 which mean invalid request.
FYI, I am using MetaQuotes-Demo account.
Thank you very much.
My code
WatchMqlTradeRequest{ action:TRADE_ACTION_PENDING magic:55555 order:0 symbol:"NZDCAD" volume:1 price:0.79 stoplimit:0.89 sl:0.86 tp:0.9 deviation:0 type:ORDER_TYPE_BUY type_filling:ORDER_FILLING_FOK type_time:ORDER_TIME_DAY expiration:D'1970.01.01 00:00:00… }
MqlTradeResult{ retcode:10013 deal:0 order:0 volume:0 price:0 bid:0 ask:0 comment:"Invalid request" request_id:2 reserved:[128] }