Alım-satım robotlarını ücretsiz olarak nasıl indirebileceğinizi izleyin
Bizi Telegram üzerinde bulun!
Fan sayfamıza katılın
Kodu ilginç mi buldunuz?
Öyleyse bir link gönderin -
başkalarının da faydalanmasını sağlayın
Kodu beğendiniz mi? MetaTrader 5 terminalinde deneyin
Kütüphaneler

OrderGuard - restart-safe order sending for EAs (no duplicate trades) - MetaTrader 5 için kütüphane

Archie Stuart Clarke
Archie Stuart Clarke
I build and fix MT5 Expert Advisors and indicators in MQL5.
Every job is tested in the MT5 Strategy Tester before delivery, and you get a short plain-English note of what was built and how it was checked. Ask for a backtest report and you get the honest numbers, good or bad.
Görüntülemeler:
73
Derecelendirme:
(1)
Yayınlandı:
\MQL5\Include\OrderGuard\ \MQL5\Experts\OrderGuardDemo\
MQL5 Freelance Bu koda dayalı bir robota veya göstergeye mi ihtiyacınız var? Freelance üzerinden sipariş edin Freelance'e git

OrderGuard is an include file for people who write their own Expert Advisors for MetaTrader 5. Its purpose is to make the way an EA sends its orders safe. It is not a robot and it has no trading strategy inside. It comes with a small example EA that shows it in use. It sends market buy and sell orders only.

It does four main things:

  • The same signal is never traded twice after a restart, a reconnect or a retry.
  • The limit on how many trades may be open is counted from the broker, not from a number that is lost when the EA restarts.
  • No orders are sent while the terminal has lost its connection, and the outage is written to the log once, not on every tick.
  • Stops and targets that sit too close to price are moved out to the broker's minimum distance and rounded properly.

Before every order it also makes these checks:

  • The lot size is fitted to what the symbol allows. It is never rounded up.
  • No order without enough free margin, none while the market is closed, none the symbol does not allow.
  • It picks a way of filling the order that the symbol accepts.
  • If the broker refuses an order, it waits a minute before trying that signal again, then longer each time (15 minutes at most).
  • A skipped signal is written to the log once, not on every tick.

How to use it: put OrderGuard.mqh in MQL5\Include\OrderGuard\ and add #include <OrderGuard\OrderGuard.mqh> to your EA. Create one COrderGuard object and call Init() with your magic number in OnInit(). Then send every order through Open() with a key that names the signal. The example EA uses the direction plus the bar's open time as the key. Open() makes all the checks above and sends the order only if that key has not been traded before.

These are faults I found and fixed on my own trading system. The example EA's entry rule (two moving averages crossing) is only there to give OrderGuard something to guard. It is not a strategy and makes no claim of profit. OrderGuard works on whatever symbol and timeframe the EA that uses it trades. Free to use and change.

Testing: Strategy Tester, H1, 1 September to 20 November 2026, hedging account. EURUSD 13 orders sent and 13 filled, USDJPY 32 and 32, US30 34 and 34, GER30 21 and 21. On all four, no signal was traded twice and no order was refused by the broker. With its memory of past signals switched off on purpose it still made 13 trades with none doubled. Asked for 500 lots, it sent no order. The picture shows these results as a table, with three lines it wrote to the journal.

Not tested: a real restart of a live terminal, a lost connection (the tester is always connected), netting accounts, gold, any other broker, real money.

Inputs of the example EA (defaults):

  • Magic number: 240117
  • Lots: 0.01
  • Fast MA period: 20
  • Slow MA period: 50
  • Stop distance, points: 300
  • Target distance, points: 600
  • Max open positions for this EA (counted from the broker): 1


Pacific Clock - US Pacific time on the chart (PST/PDT) Pacific Clock - US Pacific time on the chart (PST/PDT)

Shows US Pacific time on the chart, with the broker's time beside it, and the Pacific time of any candle under the mouse.

Lot Size Calculator - Risk Percent to Lots Lot Size Calculator - Risk Percent to Lots

Calculates the correct lot size from your risk (% of balance, % of equity or a fixed amount) and stop-loss distance. Shows actual risk and margin. Never places trades.

Key Levels: PDH/PDL, weekly and monthly levels, midnight open, Asian range, sweeps Key Levels: PDH/PDL, weekly and monthly levels, midnight open, Asian range, sweeps

Previous day, week and month high and low, New York midnight open, period opens and the Asian range, with sweep marks and one alert per level. Day from broker or New York time. No repaint, buffers for EAs.

Divergence Detector without repaint: RSI, MACD, Stochastic, CCI, Momentum Divergence Detector without repaint: RSI, MACD, Stochastic, CCI, Momentum

Regular and hidden divergences between price and RSI, MACD, Stochastic, CCI or Momentum. Swings confirmed on closed bars, signal on the confirmation bar, lines on oscillator and price. No repaint, buffers for EAs.