Invalid Trade Request when I call OrderSend(request,result) even though I have all properties included

 

Can't figure this out.  I am calling a market buy/sell and provide all properties that are required with values, but yet I continually get "Invalid Request" in the error message. When it prints out, all properties have the correct values, but the request still is invalid.  Is there something else I need to be doing for this?


void TradingLogic::OpenTrade(string comment)
  {
   double price = orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT || orderType == ORDER_TYPE_SELL ? SymbolInfoDouble(_Symbol, SYMBOL_BID) :
                  SymbolInfoDouble(_Symbol, SYMBOL_ASK); // Current bid price for sell orders, ask price for buy orders

   MqlTradeRequest request;
   MqlTradeResult result;

//action
//symbol
//volume
//price
//sl
//tp
//deviation
//type
//type_filling
//Also it is possible to specify the "magic" and "comment" field values.

// Fill in the trade request parameters
   request.action = TRADE_ACTION_DEAL;
   request.symbol = _Symbol;
   request.volume = moneyManagement.CalculateLotSize(AccountInfoDouble(ACCOUNT_BALANCE), stopLoss, automaticallyCalculateLotSize);
   request.price = price;
   //request.sl = orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT || orderType == ORDER_TYPE_SELL ? price + (stopLoss*_Point): price - (stopLoss*_Point);
   request.tp = orderType == ORDER_TYPE_SELL_STOP || orderType == ORDER_TYPE_SELL_LIMIT || orderType == ORDER_TYPE_SELL ? price - (takeProfit*_Point): price + (takeProfit*_Point);
   request.deviation  = (ulong)maxSlippage;
   request.comment = comment;
   request.magic = magicNumber;
   request.type = orderType;
   request.type_filling = ORDER_FILLING_IOC;
   Print("-----------Opening Trade!-----------");
   Print("order_type: " + (string)orderType + "| symbol: " + _Symbol + "| lot_size: " + (string)request.volume + "| price: " + (string)price + "| stop_loss: " + (string)stopLoss + "| take_profit: " + (string)takeProfit + "| comment: " + comment + "| magic_number: " + (string)magicNumber);
   Print("------------------------------------");

//--- reset the last error code to zero
   ResetLastError();
//--- send request
   bool success=OrderSend(request,result);
 
Matt E:

Can't figure this out.  I am calling a market buy/sell and provide all properties that are required with values, but yet I continually get "Invalid Request" in the error message. When it prints out, all properties have the correct values, but the request still is invalid.  Is there something else I need to be doing for this?


What is the error code?
 

Hi

Try adding “ZeroMemory(request);” before updating the request, maybe some old information are “influencing” the request and causing the problem. When you reset the memory, it should be better.

If problem still occurs, write the correct error you get – maybe this would be more helpful to discover the real reason of the problem.

Best Regards

Reason: