Watch how to download trading robots for free
Find us on Twitter!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Views:
19400
Rating:
(57)
Published:
2013.03.12 08:18
Updated:
2016.11.22 07:32

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
);

Translated from Russian by MetaQuotes Ltd.
Original code: https://www.mql5.com/ru/code/1578

WeeklyPivot WeeklyPivot

The indicator of reversal points drawn on the week candlesticks

TrendRange TrendRange

The trend indicator with three states.

MinPriceChange MinPriceChange

The indicator of the minimum sum of price changes which forms signals after flat movements and before potential breakthrough in this or that side

The scripts for opening long positions The scripts for opening long positions

These scripts are designed to buy with fixed values of Stop Loss and Take Profit in points from the current price