Guarda come scaricare robot di trading gratuitamente
Ci trovi su Twitter!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Librerie

Safe Pyramiding - add to winning trades only when they are risk free - libreria per MetaTrader 5

Lukas Szyry
Lukas Szyry
Gold Trading Specialist | XAUUSD Expert Advisors
Sviluppo Expert Advisor basati su regole per l'oro (XAUUSD) su MetaTrader 5. Mi concentro su sistemi robusti per la crescita del conto a lungo termine: niente martingala, niente griglia, nessuna mediazione al ribasso.
Visualizzazioni:
80
Pubblicato:
Freelance MQL5 Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

Pyramiding can make a good trend trade much better, but done wrong it turns one winner into a big loser. This small include only allows an add when it is safe:

  • every open position in that direction already has the stop on break-even or better
  • the newest position is at least x R in profit (R = stop distance of the first trade)
  • the max number of adds is not reached
  • the stop of the add respects the stops level and there is enough free margin

The add gets the same stop distance as the first trade and a smaller lot (for example 0.5x). So at any time the open risk is never more than the risk of one add.

Demo EA in the tester: break-even, then two adds

Functions

pyr.Setup(magic, 2, 1.0, 0.5) - max 2 adds, add every +1R, add lot = half of the first lot
LS_Pyramid::Remember(ticket, open, sl) - call after every entry, stores the stop distance (survives a terminal restart)
pyr.CanAdd(POSITION_TYPE_BUY, lot, sl) - true if an add is allowed, gives you lot and stop
pyr.Verbose(true) - prints in the journal why there is no add

Usage

#include <LS_Pyramid.mqh>
LS_Pyramid pyr;
pyr.Setup(12345, 2, 1.0, 0.5);
// after EVERY entry (first trade and adds):
LS_Pyramid::Remember(positionTicket, openPrice, sl);
// later, e.g. on a new bar and only if your signal still confirms:
double lot, sl;
if(pyr.CanAdd(POSITION_TYPE_BUY, lot, sl))
   trade.Buy(lot, _Symbol, 0, sl);

The file only decides, it doesnt open trades. Your EA opens the order, so your own filters (signal still valid, spread, session, news) stay in control. Hedging accounts only, on netting it always returns false.

To get the stops to break-even the package uses LS_StopManager.mqh (my break-even and trailing stop library: https://www.mql5.com/en/code/79902), but your own code works too.

Demo EA

The demo EA doesnt open trades on a real or demo account, it only prints when an add to your positions would be allowed. In the strategy tester it opens an example buy, moves the stop to break-even and really adds, so you can watch it in the journal (picture above: XAUUSD H1, October 2026).

The lot size calculator that fits to it: https://www.mql5.com/en/code/79855

Risk Lot Line: lot size from a draggable stop loss Risk Lot Line: lot size from a draggable stop loss

Drag a stop-loss line and read the lot size for your risk. The loss per lot comes from OrderCalcProfit, so the size is right on metals, indices and cross pairs. Shows the real risk after rounding, the margin and an R-multiple take profit. Places no orders.

Import Ticks CSV - a tick file into a custom symbol for real-tick tests Import Ticks CSV - a tick file into a custom symbol for real-tick tests

A script that reads a tick CSV into a custom symbol and builds its M1 bars, so the Strategy Tester can run "Every tick based on real ticks" over a period the broker's server does not keep. It finds the columns by name and moves UTC times to server time.

EzoO Candle Timer - time left on the candle, live spread and today's range EzoO Candle Timer - time left on the candle, live spread and today's range

Shows the time left on the current candle, the live spread and today's range next to the price or in a chart corner. Works on every timeframe.

EzoO Prev Levels - previous day high/low/open/close, previous week high/low and today's open EzoO Prev Levels - previous day high/low/open/close, previous week high/low and today's open

Previous day high/low/open/close, previous week high/low and today's open, drawn as a segment for each of the last N days with price labels.