simple trailing position management library

simple trailing position management library
Download ALL MT4 experts (879)
YouTube Video Thumbnail



Similar MetaTrader Tools

simple trailing position management library

Info

The simple trailing position management library is a Expert Advisor for MetaTrader 4 that simple trailing position management library this library provides functions for managing open positions using a simple trailing stop mechanism. it is designed to be integrated into any expert advisor (ea) and supports two trailing modes, switchable via the profittrailing parameter.

Usage

This tool is typically used for automated trading on major forex pairs and gold.

Platform

This Expert Advisor works exclusively on MetaTrader 4 (both build 600+ and newer versions).

Setup

Place the downloaded file in MQL4/Experts folder via File ? Open Data Folder in MetaTrader 4.


How to Install and Use simple trailing position management library

1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.

2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.

3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.

4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.

Frequently Asked Questions

Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.

Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.

Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.

What this tool does

simple trailing position management library this library provides functions for managing open positions using a simple trailing stop mechanism.

Typical Use Case

This Expert Advisor excels in automated trading and technical analysis on MetaTrader 4.

Compatible Platform & Setup

This Expert Advisor works on MetaTrader 4. Place the file in the MQL4/Experts folder and restart the terminal.

Description & Settings

Related: e-trailing2: enhanced trailing stop expert advisor - another powerful expert for MetaTrader 4 traders.

simple trailing position management library this library provides functions for managing open positions using a simple trailing stop mechanism. it is designed to be integrated into any expert advisor (ea) and supports two trailing modes, switchable via the profittrailing parameter. the library's functionality closely mirrors the trailing stop mechanism found in the e-trailing ea. the primary distinction of this library is its ability to set different trailing stop sizes for buy and sell positions. to use the a-simpletrailing.mqh library in your ea: 1. place the a-simpletrailing.mqh file into the ..\experts\include\ directory.

Also recommended: e-trailing: automated trailing stop for all positions - similar expert with strong performance on MetaTrader 4.

2. at the top of your ea's code, before any function declarations, add the following line:
#include <a-simpletrailing.mqh>
3. in your ea's start() function, add the following line:
if (usetrailing) trailingpositions();
refer to the examples provided for the main library function to select specific parameters.
after integrating the library, your ea will have access to the following additional external parameters: usetrailing=true - enables or disables the trailing stop. if true, the trailing stop is active; if false, it is inactive.
profittrailing=true - trailing only on profit. the trailing stop activates only when the profit of the managed position exceeds the trailing stop size plus the trailing step. if false, the trailing stop begins operating even in a loss zone. this feature can be utilized to set stop levels for breakeven positions at the trailing stop size.
trailingstopbuy=50 - the fixed trailing stop size for buy positions.
trailingstopsell=50 - the fixed trailing stop size for sell positions.
trailingstep=5 - the step size for the trailing stop.
the main library function, trailingpositions(), accepts the following parameters: sy - the instrument name (default is "" for the current symbol).
op - the operation type (-1 for any position).
mn - the magic number (-1 for any magic number).
default values for parameters are indicated in parentheses and can be omitted.
examples of using the main library function: trailingpositions() - manages any positions with any magic number on the current instrument.
trailingpositions("", -1, magic) - manages any positions with a magic number equal to 'magic' on the current instrument.
trailingpositions("", op_sell) - manages sell positions with any magic number on the current instrument.
trailingpositions("usdjpy", op_buy, magic) - manages buy positions with a magic number equal to 'magic' on the usdjpy instrument.
for the library to function correctly, global variables are required. it is recommended to define these within your ea's code:
clmodifybuy - the color for the buy modification indicator.
clmodifysell - the color for the sell modification indicator.
additionally, you must include the universal order and position modification function, modifyorder(), within your ea's code.

You may also like: simple trailing stop - excellent alternative for expert users on MetaTrader 4.

Source Code

extern string _P_Trailing = "---------- Параметры трала";
extern bool UseTrailing      = True;        // Использовать трал
extern bool ProfitTrailing   = True;        // Тралить только профит
extern int  TrailingStopBuy  = 50;          // Фиксированный размер трала
extern int  TrailingStopSell = 50;          // Фиксированный размер трала
extern int  TrailingStep     = 5;           // Шаг трала
void TrailingPositions(string sy="", int op=-1, int mn=-1) {
double p, pp;
int    i, k=OrdersTotal();
if (sy=="") sy=Symbol();

.......

Leave your opinion, ask a question, share some knowledge

Limitations & Risk Warning

  • This tool is provided for educational and testing purposes only.
  • Past performance does not guarantee future results.
  • Trading involves substantial risk of loss. Use on a demo account first.
  • Results may vary depending on market conditions, broker, and settings.
  • We recommend thorough backtesting and forward testing before using with real funds.
© ROBOTFX Free educational tools by RobotFX. Use entirely at your own risk; we are not liable for any financial losses incurred.