Loading…

Compression Scaled Straddle System

A plain "buy stop above, sell stop below" straddle on a tight range treats every squeeze the same. In practice a compression that has run far longer than this symbol's own recent average tends to release a larger move once it finally lets go, and a fixed lot size leaves that information on the table. This EA measures compression as the combined high-low range of the last few closed bars sitting below a fraction of the current ATR. While the market stays compressed it counts consecutive bars in the episode; once that count reaches the minimum duration, it arms one straddle - a BuyStop above the box high and a SellStop below the box low, both with a real stop and target, both magic-scoped and mutually exclusive (OCO): the instant one leg fills the other is deleted rather than left resting as an orphan. The sizing idea is the point of the project: every completed compression's duration is logged into a rolling window, and the lot for a NEW straddle is scaled by how many standard deviations the current episode's duration sits above that logged mean, capped by InpMaxSizeMultiplier. A first-ever episode with no logged history yet simply trades the base lot - the statistical edge only sharpens as the symbol builds its own track record on this chart. Untriggered legs expire on a real clock deadline (converted from InpExpiryBars at placement time, not polled bar by bar), and if the compression itself ends without triggering, the stale pendings are pulled immediately rather than left to sit against a box that no longer describes the market. Notes and limitations - Sizing only ever scales UP from the base lot for a longer-than- average compression; a shorter-than-average one simply trades the base lot, it is never downsized below it. - The duration log is per chart/session in memory - it resets when the EA is removed or the terminal restarts, and starts empty on a freshly attached chart, so sizing statistics build up over time rather than existing from the first run. - One straddle episode at a time per chart. A second compression forming while a position from the first is still open is not straddled again until that position closes. - This is a breakout system: it can be stopped out repeatedly during a choppy, range-bound market that keeps compressing and failing to break out cleanly. Conservative defaults are provided but no sizing scheme replaces a trader's own risk limits.

Expert advisor · MT5 · v1.0 · Free

About Compression Scaled Straddle System

Compression Scaled Straddle System is an expert advisor (trading robot) for MetaTrader 5 based on ATR. It increases the lot size after a losing trade (martingale) and places pending buy/sell stop or limit orders. It has 15 settings, such as Atr period, Range bars and Compression ratio. MQL source code included.

Files in the download: CompressionScaledStraddle.ex5, CompressionScaledStraddle.mq5, CompressionScaledStraddle.txt.

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

Settings

SettingDefaultWhat it does
Atr period14ATR period used as the volatility yardstick
Range bars4Bars whose combined high-low range defines "the box"
Compression ratio0.65Box range must be below this fraction of ATR to count as compressed
Min duration bars6Minimum consecutive compressed bars before a straddle is armed
Stats window30How many completed compression durations feed the mean/stdev
Base lots0.10Lot size for an average-duration compression
Max size multiplier2.5Cap on how far a long compression can scale the base lot
Box buffer pips3.0Distance, in pips, pending legs sit outside the box edges
Expiry bars20Untriggered legs expire after this many bars (converted to a clock deadline)
Stop pips0Optional stop-loss distance in pips for the filled leg, 0 = none
Target rr1.5Take-profit as a multiple of the box height, 0 = no target
Magic number20260379Magic number for orders placed by this EA
Slippage pips3Slippage tolerance, in pips
Max retries5Attempts per order before giving up
Retry wait ms500Pause between attempts, milliseconds

How to install

  1. Download the ZIP from your PolyMaria library and unzip it.
  2. In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Experts.
  3. Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
  4. Open the .mq5 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: Risk & Lot Size · Pending Orders · Martingale · ATR · MT5 Expert Advisor · MQL5 Source Code

Expert advisors (EA) for MT4 & MT5 · PolyMaria