'request' - undeclared identifier, why am I getting this error?

Viewed 22

I believe I am doing the exact same as in the MQl5 guide, 820 and 1517.

Could someone tell me what I am doing wrong?

//--- Preparing the request 
double BuyAsync(double volume)
   {MqlTradeRequest request={};
      request.price        =     SymbolInfoDouble(_Symbol(),SYMBOL_ASK);   // Long
      request.magic        =     EXPERT_MAGIC;                 // EA magic number so you can track trades 
      request.action       =     TRADE_ACTION_DEAL;            // Market order
      request.symbol       =     "EURUSD";                     // Symbol 
      request.type         =     ORDER_TYPE_BUY;               // Long
      request.order        =     "OrderTicketBuy";             // The orderticket so you can trace the individual trade 
      request.deviation    =     5;                            // Maximum price deviation 
      request.volume       =     0.25;                         // This should be €25.000 
      request.tp           =     tpLong;                       // Take profit long 
      request.sl           =     slLong;                       // Stoploss long
      request.comment      =     "Buy using OrderSendAsync()";
   MqlTradeResult result={};
   if(!OrderSendAsync(request,result))
     {
      Print(__FUNCTION__,": error ", GetLastError(),", retcode = ", result.retcode);
     }
  }

Thanks in advance!

3 Answers

instead of this:

MqlTradeRequest request={};

use this:

MqlTradeRequest request;

do same for the request

#include <Trade\Trade.mqh>

CTrade trade;

void OnInit()


{
double vol=0.01;
double selling_price=SymbolInfoDouble(_Symbol,SYMBOL_BID);
double buying_price=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
trade.Sell(vol,_Symbol,selling_price,0,0);
trade.Buy(vol,_Symbol,buying_price,0,0);
}

this is just a simple example, i haven't used stop loss of take profit, i have just opened the trade u can modify the stop loss and take profit.Hope my effort makes a difference for you.

If it helps anyone, this is the answer to the original question:

//--- Preparing the request 
void BuyAsync()
   {MqlTradeRequest request={};
      request.price        =     SymbolInfoDouble(_Symbol,SYMBOL_ASK);   // Long
      request.magic        =     EXPERT_MAGIC;                 // EA magic number so you can track trades 
      request.action       =     TRADE_ACTION_DEAL;            // Market order
      request.symbol       =     _Symbol;                      // Symbol 
      request.type         =     ORDER_TYPE_BUY;               // Long
      request.order        =     "OrderTicketBuy";             // The orderticket so you can trace the individual trade 
      request.deviation    =     5;                            // Maximum price deviation 
      request.volume       =     0.25;                         // This should be €25.000 
      request.tp           =     tpLong;                       // Take profit long 
      request.sl           =     slLong;                       // Stoploss long
      request.comment      =     "Buy using OrderSendAsync()";
   MqlTradeResult result={};
   if(!OrderSendAsync(request,result))
     {
      Print(__FUNCTION__,": error ", GetLastError(),", retcode = ", result.retcode);
     }

The difference is in the first couple of lines.

Related