declare and initialize the trade request and result

 

Hi

Reading code examples in the Documentations, why there are times when this line is used for opening positions

MqlTradeRequest request={0};

but other times, this line is used for closing positions

MqlTradeRequest request;

Is this how to initialise the struct in mql5? but why leave out the "{0}" or put it in for both examples?


Thanks

Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
Documentation on MQL5: Standard Constants, Enumerations and Structures / Trade Constants / Trade Operation Types
  • www.mql5.com
Trading is done by sending orders to open positions using the OrderSend() function, as well as to place, modify or delete pending orders. Each trade order refers to the type of the requested operation. Trading operations are described in the ENUM_TRADE_REQUEST_ACTIONS enumeration...
 
Is this how to initialise the struct in mql5?

Per: https://www.mql5.com/en/docs/basis/variables/initialization

//--- initialization of all fields of the structure with zero values
MqlTradeRequest request={0};
but why leave out the "{0}" or put it in for both examples?

The documentation is rather voluminous and perhaps written by many people at different times.

 
samjesse:

Hi

Reading code examples in the Documentations, why there are times when this line is used for opening positions

but other times, this line is used for closing positions

Is this how to initialize the struct in mql5? but why leave out the "{0}" or put it in for both examples?


Thanks

MqlTradeRequest request={0};
MqlTradeRequest EmptyTradeRequest={0}

request.action = TRADE_ACTION_DEAL;
request = EmptyTradeRequest;
Just create an empty trade request and use it to clean ups.
 
Arthur Albano:
Just create an empty trade request and use it to clean ups.

Or, perhaps, you could try:

ZeroMemory(request);
Reason: