Voir comment télécharger gratuitement des robots de trading
Retrouvez-nous sur Facebook !
Rejoignez notre page de fans
Un script intéressant ?
Poster un lien vers celui-ci -
laisser les autres l'évaluer
Vous avez aimé le script ? Essayez-le dans le terminal MetaTrader 5
Bibliothèque

ATS Trade Management Library - break-even, trailing stop and partial closes for any EA - bibliothèque pour MetaTrader 5

Vues:
78
Note:
(1)
Publié:
Mise à jour:
MQL5 Freelance Besoin d'un robot ou d'un indicateur basé sur ce code ? Commandez-le sur Freelance Aller sur Freelance

A small include file that looks after the positions an EA, a trader or another EA has already opened. It only moves stops and closes part or all of a position. It never opens a trade.

What it does

  • Break-even: moves the stop to the entry (plus an offset) once the position is far enough in profit. The trigger is set in R (multiples of the initial stop), in ATR or in points.
  • Trailing stop: a fixed distance behind the price, or behind the lowest low / highest high of the last N closed candles on the timeframe you choose. The stop only moves in your favour, in steps you set.
  • Two partial closes: a share of the position at the first level, a share of the ORIGINAL position at the second, with an optional move to break-even after the first. The lot of a partial close is floored to the volume step and never leaves less than the minimum lot.
  • A stop and a target for positions that have none (for example trades opened from a phone): a stop at ATR multiples or a number of points, a target at a number of R.
  • Every symbol or one symbol, every magic number or a list (0 = trades opened by hand).

How it works

  • "R" is the distance between the entry and the stop the position had when the library first saw it. A position without a stop has no R: the rules set in R skip it, so use ATR or points (or the automatic stop) for those.
  • What was already done on a position (break-even moved, partial closes made) is saved in GlobalVariables, so a restart of the terminal does not repeat it.
  • Stops that are closer to the price than the broker's stop level are not sent; the library tries again on the next pass.
  • The calculations are plain functions with no terminal data, so they can be tested with fixed numbers: the included self-test runs 36 checks.

Use

#include "ATS_TradeMgmtLib.mqh"
CAtsTradeMgmt mgmt;
SAtsMgmtConfig cfg;  mgmt.DefaultConfig(cfg);
cfg.useBreakEven = true;  cfg.beUnit = ATS_UNIT_R;  cfg.beTrigger = 1.0;
cfg.trailMode = ATS_TRAIL_CANDLES;  cfg.trailBars = 3;  cfg.trailStart = 1.5;
mgmt.Init(cfg, "", "");           // every symbol, every magic number
// in OnTimer(): mgmt.ManageAll();

The package: ATS_TradeMgmtLib.mqh (the library), ATS_TradeMgmt_Demo.mq5 (an example EA, a trade manager in a few lines), ATS_TradeMgmt_SelfTest.mq5 (36 checks of the calculations, run it as a script).

Good to know

  • It does not give signals and promises no result. A stop can be filled at a worse price in a fast market, as with any stop.
  • The terminal and the EA must be running when the price moves.
  • Tested in the Strategy Tester (positions opened every day, break-even, both partial closes, trailing stop and the automatic stop and target all acted as expected) and on a demo account, on hedging accounts. It works on netting accounts too: partial closes act on the position.

Session Reality Auditor Session Reality Auditor

Checks the broker's session table against the M1 history. For every minute of the week it counts on how many of the last N days the symbol really has a bar, and sets that next to SymbolInfoSessionQuote and SymbolInfoSessionTrade: declared minutes that are usually empty (rollover holes), bars in minutes the table calls closed, trade and quote tables that disagree, and one-off outages such as an early holiday close. Prints the real sessions per weekday, writes every finding to CSV and prints its own arithmetic. Read only: no trade function, no DLL, no network.

Advanced Prop-firm Trade Panel based on S-R Advanced Prop-firm Trade Panel based on S-R

A manual trading panel with a built-in prop-firm risk guard and a hidden Support/Resistance finder for MetaTrader 5.

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

MACD Signals MACD Signals

Indicator edition for new platform.