Example a EA of moving average sma5 and sma20 cross

 

Hello everyone,

Moving from mql4 to mql5, I'm trying to code a simple EA to know about mql5 (coding an EA with MA5 and MA20 cross). But i'm very confuse to place an order buy (or send) by OrderSend and OrderSendAsync. Anyone can share to me a example about place order on mql5, please ?

Thank you so much.

Tomq

 
    bool result = trade.Buy(lotSize, _Symbol, 0, sl, tp, "Market Buy Order");  // Place a buy order

    if (!result)
    {
        Print("OrderSend failed, error code =", GetLastError());
    }
    else
    {
        Print("OrderSend successful");
    }

To place orders, you can use the CTrade class and its OrderSend method, this is very similar to MQL4. Just declare the CTrade class:

#include <Trade\Trade.mqh>  // Include the trade functions library

CTrade trade;  // Create an instance of the CTrade class
 
Frederic Metraux #:

To place orders, you can use the CTrade class and its OrderSend method, this is very similar to MQL4. Just declare the CTrade class:

Thank you Frederic,

So, when are OrderSend and OrderSendAsync used? And how about OrderModify a order ? 

 
Tomq #:

Thank you Frederic,

So, when are OrderSend and OrderSendAsync used? And how about OrderModify a order ? 

Those are MT4 functions.

trade.PositionModify() in MT5 with the trade library


 
Conor Mcnamara #:
Those are MT4 functions.

trade.PositionModify() in MT5 with the trade library


Great. Thank you