Loading…

Order Send Retry Pattern Demo

A huge number of published experts retry a failed trade request the same broken way: catch any non-success result, wait a fixed half second, try again, up to some fixed count. That treats a requote the same as trading being disabled outright, when one of those is worth trying again in a moment and the other means stop, because retrying it will never succeed and just spams the trade server and the log. This script exists to make the correct version visible, not just describe it in a comment somewhere. It has two moving parts, and beginners usually get at least one of them wrong: classification, where retryable results like requotes, timeouts and a busy server get another attempt while permanent ones like invalid stops or disabled trading stop the loop immediately; and backoff, where the wait between attempts grows instead of staying fixed, so a server that is briefly overloaded gets breathing room instead of a hammering that makes the problem worse. By default nothing is sent anywhere. Dry-run mode simulates a sequence of injected transient failures and walks through exactly the same decision logic the live version uses, printing each classification and backoff calculation as it happens, so the pattern can be studied with zero risk and no account needed at all. Switching dry-run off sends one real order through the identical loop and closes it immediately once filled - useful for confirming the pattern against a specific broker's actual timeout and requote behaviour, not just against a simulation of it. Notes and limitations - Dry-run mode touches no account and sends nothing - it is a safe way to read the pattern's decisions without a connected broker at all. - Live mode sends one real order at the symbol's minimum lot and closes it immediately once filled. It still carries real execution risk, which is why the demo-account check and confirmation prompt exist. - The injected failures in dry-run mode are a fixed, repeating list chosen to exercise the retryable branch; a real broker's actual mix of transient results will differ. - This is a teaching pattern, not a production order-management module - a real expert would wrap this logic around its own position sizing, and most would collect tickets and retry per-order in a batch, the way the house style's own reference scripts do. - The MQL5 live leg refuses to send if the target symbol already has an open position on a netting account. The MQL4 version has no equivalent check because MQL4 has no netting model.

Script · MT4 · v1.0 · Free

About Order Send Retry Pattern Demo

Order Send Retry Pattern Demo is an expert advisor (trading robot) for MetaTrader 4. It has 7 settings, such as Dry run, Simulated failures and Max retries. MQL source code included.

Files in the download: OrderSendRetryPatternDemo.ex4, OrderSendRetryPatternDemo.mq4, OrderSendRetryPatternDemo.txt.

Trading robots can lose money. Check every setting and test on a demo account before using real funds.

Settings

SettingDefaultWhat it does
Dry runtrueSimulate the retry loop instead of sending a real order
Simulated failures3Dry run only: how many injected failures before success
Max retries5Attempts before giving up
Base retry wait ms300First backoff wait, milliseconds
Max retry wait ms5000Backoff wait is capped at this
Require demo accounttrueLive mode only: refuse to run on anything but a demo account
Confirm firsttrueLive mode only: ask for confirmation before sending

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
  3. Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
  4. Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
  5. Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
  6. Test it first on a demo account or in the Strategy Tester.

Download the PDF guide

Tags: MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria