Simple Trade Opening Script

 

I'm trying to work with MqlTradeRequest to make a simple script that just opens an order. I simply copied and pasted the script from the mql documentation, but it's not working for me. The MqlTradeRequest and MqlTradeResult don't highlight pink when I type them. I'm getting lots of errors, I imagine most of which have to do with it not recognizing the MqlTradeResult ('MqlTradeRequest' - undeclared identifier). This wouldn't have anything to do with a difference with mql4 and mql5 would it? What would the problem be?


void OnStart()
  {
//---
   MqlTradeRequest request={0};
   MqlTradeResult  result={0};
//--- parameters of request
   request.action   =TRADE_ACTION_DEAL;                     // type of trade operation
   request.symbol   =Symbol();                              // symbol
   request.volume   =0.1;                                   // volume of 0.1 lot
   request.type     =ORDER_TYPE_BUY;                        // order type
   request.price    =SymbolInfoDouble(Symbol(),SYMBOL_ASK); // price for opening
   request.deviation=5;                                     // allowed deviation from the price
   request.magic    =3;                                     // MagicNumber of the order
//--- send the request
   if(!OrderSend(request,result))
      PrintFormat("OrderSend error %d",GetLastError());     // if unable to send the request, output the error code
//--- information about the operation
   PrintFormat("retcode=%u  deal=%I64u  order=%I64u",result.retcode,result.deal,result.order);
  }
//+------------------------------------------------------------------+


It seems to highlight pink when I post here, but not on my MetaEditor. If its a problem with the version, how would I do this in mql4?

 
Drew Clayman:

I'm trying to work with MqlTradeRequest to make a simple script that just opens an order. I simply copied and pasted the script from the mql documentation, but it's not working for me. The MqlTradeRequest and MqlTradeResult don't highlight pink when I type them. I'm getting lots of errors, I imagine most of which have to do with it not recognizing the MqlTradeResult ('MqlTradeRequest' - undeclared identifier). This wouldn't have anything to do with a difference with mql4 and mql5 would it? What would the problem be?



It seems to highlight pink when I post here, but not on my MetaEditor. If its a problem with the version, how would I do this in mql4?

https://docs.mql4.com/trading/ordersend
OrderSend - Trade Functions - MQL4 Reference
OrderSend - Trade Functions - MQL4 Reference
  • docs.mql4.com
Returns number of the ticket assigned to the order by the trade server or -1 if it fails. To get additional error information, one has to call the GetLastError() function. At opening of a market order (OP_SELL or OP_BUY), only the latest prices of Bid (for selling) or Ask (for buying) can be used as open price. If operation is performed with a...
Reason: