Straddle Around Price
Before a news release the honest position is "I do not know which way it goes". The straddle expresses exactly that: a buy stop above the market, a sell stop below, and whichever way price breaks, one of them is carried in. First the honesty, because most straddle scripts skip it. MetaTrader has no native one-cancels-the-other for retail pending orders, and a script ends the moment it returns - it cannot sit and watch for a fill, so it CANNOT cancel the losing leg for you. Anything that claims otherwise is either secretly an expert advisor or wrong. This script places both legs with a shared comment tag (OCO-<id>, also printed to the journal), so the companion OCO Order Manager expert from this series - or you, by hand - can cancel the surviving leg. The confirmation dialog and the final alert both repeat this, so nobody walks away believing the pair manages itself. Each leg is sized with proper risk arithmetic: pip value per lot is derived as tick value * (pip size / tick size), which stays correct on JPY crosses, gold and index CFDs where naive Point arithmetic mis-sizes by up to an order of magnitude. The volume is floored to the lot grid and never rounded up; if even the minimum lot would exceed the per-leg budget, the script refuses and prints the nearest workable risk and stop settings instead of quietly oversizing. The whipsaw case is stated in numbers before you commit: on a hedging account both legs can trigger and both stops can be hit - roughly twice the per-leg risk. Trigger distances and stop offsets are validated against the broker's stop and freeze levels on every attempt, because those widen during exactly the news this script is built for. If the second leg cannot be placed, the first is rolled back so a half straddle - a directional bet you never asked for - is not left behind. Notes and limitations - No leg is cancelled automatically when the other fills. That requires a program that stays resident - see the OCO Order Manager expert - or your own hand. This is a platform limit, not an oversight. - The OCO-<id> tag lives in the order comment, and some brokers overwrite comments on partial fills or internal operations. The journal line with both tickets is the durable record. - Slippage on a news spike can fill a stop order well past its price; the stop loss then sits at its absolute level, so the realised risk can exceed the budget in a fast market. No retail order type prevents that. - Spread widening at the release can trigger a leg without the underlying price moving - that is the broker's quote doing it, not a bug. Distances under 10 pips on majors are asking for it. - Each leg is sized in isolation against the chosen base; the script does not track account-wide open risk.
Script · MT4 · v1.0 · Free
About Straddle Around Price
Straddle Around Price is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders and can size trades from your balance and risk percent. It has 11 settings, such as Distance pips, Risk base and Risk percent. MQL source code included.
Files in the download: StraddleAroundPrice.ex4, StraddleAroundPrice.mq4, StraddleAroundPrice.txt.
Trading robots can lose money. Check every setting and test on a demo account before using real funds.
Settings
| Setting | Default | What it does |
|---|---|---|
| Distance pips | 20.0 | Distance to each stop order, pips |
| Risk base | RISK_BASE_BALANCE | Risk is a percent of |
| Risk percent | 1.0 | Risk per leg, percent |
| Stop pips | 20.0 | Stop loss per leg, pips |
| Take profit r | 0.0 | Take profit, R multiple (0 = none) |
| Expiry | D'1970.01.01' | Expiry (leave 1970 = no expiry) |
| Oco id | 0 | OCO pair id (0 = generate) |
| Magic | 0 | Magic number |
| Max retries | 5 | Attempts before giving up |
| Retry wait ms | 500 | Pause between attempts, ms |
| Confirm first | true | Ask for confirmation first |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 4 open File → Open Data Folder, then go to MQL4 → Experts.
- Copy the .mq4 file(s) there. Put any .mqh files in MQL4 → Include.
- Open the .mq4 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the expert advisor from the Navigator onto a chart, check the settings, allow Algo/Auto Trading and press OK.
- Test it first on a demo account or in the Strategy Tester.
Tags: News Trading · Pending Orders · Risk & Lot Size · MT4 Script · MQL4 Source Code