Loading…

Broker Scenario Scripter

Retry and error-handling logic around OrderSend is usually only ever tested against a single injected failure - "what happens if this one call returns ERR_REQUOTE" - which is not what a real bad session looks like. A real dealing desk having a rough few seconds produces a PATTERN: several requotes in a row while the price is moving fast, then a connection blip that rejects a couple of attempts outright, then things settle down. Retry logic that only survives a single isolated failure can still give up too early, or hammer the server too fast, against that realistic shape. BssScriptRequoteStorm, BssScriptErrorBurst and BssScriptPartialFill let a test set up that whole pattern in three calls, keyed to the OrderSend CALL INDEX rather than injected live - "calls 2 through 5 requote, call 6 partially fills, calls 7 and 8 hit a server-busy burst" - then replay it deterministically by driving BssSimulateOrderSend through a loop. The call counter advances on every attempt, including a rejected one, matching how a real requote sequence is actually counted. This catalogue already has MockTradeServer.mqh, a general-purpose in-memory broker simulator supporting the full order-pool API (OrderSelect/OrderClose/OrderModify, history, live profit marking) with one-shot FIFO error injection. Every submission in this catalogue must be self-contained - no #include of another project's header - so this is a fresh, standalone implementation referencing that design rather than reusing its code, and it is deliberately narrower: OrderSend only, no order-pool simulation, no P&L tracking. What it adds instead is the one thing MockTradeServer's one-shot queue does not give you: an event TIMELINE scripted by call index up front, so a whole storm/burst pattern is one setup call instead of one MockQueueError per call, useful specifically for retry-loop and backoff testing rather than general order-lifecycle testing. Notes and limitations - OrderSend only. There is no OrderSelect/OrderClose/OrderModify, no order pool, and no history - this header scripts SEND-time failure timing, nothing about an order's later lifecycle. Use MockTradeServer.mqh (a separate entry in this catalogue) when a test needs the full trade lifecycle instead. - A scripted requote or error rejection performs NO price-tolerance check - it fires unconditionally at its call index regardless of how close the caller's price argument is to the current quote. An UNscripted call still goes through the ordinary drift check against BssSetPrice's current bid/ask, exactly as a real OrderSend would. - The call index counts every BssSimulateOrderSend call, including ones for a different symbol - there is no independent per-symbol counter. A test mixing symbols in one script should account for that shared counter when picking call indices. - No random behaviour anywhere - a scripted timeline replays identically every run, which is the point (deterministic retry-logic testing), but means this header does not model the natural variation a live requote's actual price drift would have. - Ticket numbers are a simple incrementing counter with no association back to symbol, price or volume - this header is for testing SEND behaviour, not for building a realistic position book.

Script · MT4 · v1.0 · Free

About Broker Scenario Scripter

Broker Scenario Scripter is an expert advisor (trading robot) for MetaTrader 4. It has 1 setting, such as Max retries per attempt. MQL source code included.

Files in the download: BrokerScenarioScripter.mqh, BrokerScenarioScripter.txt, BrokerScenarioScripterDemo.mq4.

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

Settings

SettingDefaultWhat it does
Max retries per attempt10Retry cap for one logical order attempt

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: Trading Sessions · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria