Loading…

Time Stop Sweep Study

"Just get out after N bars" is a common exit idea, but it is rarely tested against the price-based alternative on the same set of trades. This script generates a comparable population of entries using a simple, deterministic Donchian-style breakout rule (close beyond the prior N bars' high or low), then runs every entry through two exit families independently: a fixed stop-loss/take-profit pair walked forward bar by bar, and a sweep of seven pure time stops (exit at market after 1, 2, 4, 8, 16, 24 and 48 H1 bars, no price condition at all). The entry rule exists only to produce a fair, repeatable population of trades to test exits against - this is a study of exit behaviour, not a claim that the breakout entry itself is profitable. Comparing the time-stop rows against the price-stop row on the same symbol and history shows whether simply capping holding time performs competitively here, worse, or better - and at which specific holding length, rather than a single guessed number. Every simulated trade is independent of every other; this script does not model position sizing, margin, spread or concurrent exposure. It answers "what would this exit have done to this entry", not "what would an account running this strategy have done". Notes and limitations - The seven time-stop lengths are a fixed internal sweep set (1, 2, 4, 8, 16, 24, 48 bars), not user-editable inputs - MQL4 has no array input type, and a fixed, documented set keeps every run directly comparable. - Entries are not filtered for overlap - two breakouts a few bars apart can both be counted, each simulated independently as its own hypothetical trade. This is deliberate for a per-trade exit study, but means the trade count is not a realistic count of positions a live strategy would actually hold at once. - Spread, commission and swap are not modelled - every outcome is a raw price-to-price distance in pips. - A time-stop row's trade count can be lower than the price-stop row's when an entry sits too close to the end of the scanned history for that holding length to complete; this is reported honestly by skipping the incomplete case rather than padding it with a guess.

Script · MT4 · v1.0 · Free

About Time Stop Sweep Study

Time Stop Sweep Study is a script for MetaTrader 4. It can alert you with a pop-up, sound, email or push message. It has 6 settings, such as Symbol, Max bars and Donchian period. MQL source code included.

Files in the download: TimeStopSweepStudy.mq4, TimeStopSweepStudy.txt.

Settings

SettingDefaultWhat it does
SymbolSymbol to study, blank = this chart's symbol
Max bars3000Most recent H1 bars to include
Donchian period20Lookback bars for the breakout entry rule
Stop loss pips40.0Price-stop exit: stop-loss distance in pips
Take profit pips60.0Price-stop exit: take-profit distance in pips
Max hold bars for sl200Price-stop exit: give up and exit at market after this many bars if neither level is touched

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 → Scripts.
  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 script onto a chart to run it once.

Download the PDF guide

Tags: Breakout · Channels & Envelopes · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria