TradeAlgorithms – library MetaTrader 5

Trade functions library designed for use in the code of scripts and Expert Advisors depending on a broker.

You can get acquainted with the Expert Advisors drawn on the basis of this library in the article “Simple Trading Systems Using Semaphore Indicators”.

As a large number of the Expert Advisors using this library was placed in Code Base, it was decided to perform four variants of its program code to use these Expert Advisors with any broker who offers trading on financial markets using MetaTrader 5 Client Terminal:

  1. For brokers who offer nonzero spread and ability to set Stop Loss and Take Profit simultaneously opening a position;
  2. For brokers who offer zero spread and ability to set Stop Loss and Take Profit simultaneously opening a position;
  3. For brokers who offer nonzero spread and Stop Loss and Take Profit setting after opening a position;
  4. For brokers who offer zero spread and Stop Loss and Take Profit setting after opening a position;

All files placed in archives have one unique name – TradeAlgorithms.mqh. For the Expert Advisors in Code Base which use this library, only one variant of TradeAlgorithms.mqh file is allowed to use under its name in the terminal_data_folder\MQL5\Include\ of one client terminal!

After moving the library file all the Expert Advisors which use it should be compiled. For this, restart MetaEditor, open the Navigator window, right click on the MQL5 label and select “Compile” in the pop-up menu.

Functions

The library contains the following main trading functions:

bool BuyPositionOpen
(
    bool &BUY_Signal,          // deal permission flag
    const string symbol,       // deal's trading pair
    const datetime &TimeLevel, // time after which the following deal after the current deal will be performed
    double Money_Management,   // MM
    int Margin_Mode,           // way of lot value calculation
    uint deviation,            // slippage
    int StopLoss,              // Stop Loss in points
    int Takeprofit             // Take Profit in points
);

bool SellPositionOpen
(
    bool &SELL_Signal,         // deal permission flag
    const string symbol,       // deal's trading pair
    const datetime &TimeLevel, // time after which the following deal after the current deal will be performed 
    double Money_Management,   // MM
    int Margin_Mode,           // way of lot value calculation
    uint deviation,            // slippage
    int StopLoss,              // Stop Loss in points
    int Takeprofit             // Take Profit in points
);

bool BuyPositionOpen
(
    bool &BUY_Signal,          // deal permission flag
    const string symbol,       // deal's trading pair
    const datetime &TimeLevel, // time after which the following deal after the current deal will be performed
    double Money_Management,   // MM
    int Margin_Mode,           // way of lot value calculation
    uint deviation,            // slippage
    double dStopLoss,          // Stop Loss in price chart units
    double dTakeprofit         // Take Profit in price chart units
);

bool SellPositionOpen
(
    bool &SELL_Signal,         // deal permission flag
    const string symbol,       // deal's trading pair
    const datetime &TimeLevel, // time after which the following deal after the current deal will be performed
    double Money_Management,   // MM
    int Margin_Mode,           // way of lot value calculation
    uint deviation,            // slippage
    double dStopLoss,          // Stop Loss in price chart units
    double dTakeprofit         // Take Profit in price chart units
);

bool BuyPositionClose
(
    bool &Signal,        // deal permission flag
    const string symbol, // deal's trading pair
    uint deviation       // slippage
);

bool SellPositionClose
(
    bool &Signal,        // deal permission flag
    const string symbol, // deal's trading pair
    uint deviation       // slippage
);

bool BuyPositionModify
(
    bool &Modify_Signal, // modification permission flag
    const string symbol, // deal's trading pair
    uint deviation,      // slippage
    int StopLoss,        // Stop Loss in points
    int Takeprofit       // Take Profit in points
);

bool SellPositionModify
(
    bool &Modify_Signal, // modification permission flag
    const string symbol, // deal's trading pair
    uint deviation,      // slippage
    int StopLoss,        // Stop Loss in points
    int Takeprofit       // Take Profit in points
);


📈 ROBOTFX MetaTrader Expert Advisors and Indicators to maximize profits and minimize the risks