Bracket From Three Lines
The complete trade plan is three prices: where to get in, where to admit the idea failed, where to take the profit. Drawn as three lines they are easy to see and easy to move around while thinking. Getting them into an order ticket by hand means retyping three five-digit numbers plus a volume you worked out on a calculator, and each of those is a place to be wrong. This script reads the three lines and builds the order. Its defining decision is that DIRECTION IS NOT AN INPUT. Stop below the entry with target above it is a buy; the mirror is a sell; anything else - stop and target on the same side, lines at equal prices - is a malformed plan and is refused with all three prices printed. A direction dropdown that can contradict the drawing is how people end up buying with their stop above the entry, and the server will happily accept that order. Geometry cannot be contradicted, so the dropdown does not exist. Sizing is by risk: the entry-to-stop distance is converted to money per lot through tick value arithmetic - not Point arithmetic, which mis-sizes metals and indices by exactly the tick-to-point ratio - and the volume is what loses the asked percentage of equity at the stop. The volume is floored to the lot step, never rounded up, so the error is always on the side of risking less than asked. If even the minimum lot would breach the asked risk, the script refuses and tells you what the minimum lot would actually risk, in money and in percent, rather than silently placing an oversized trade. The pending type - stop or limit - comes from the entry's side of the market. Missing or mistyped line names get the same treatment as the rest: every horizontal line on the chart is listed in the log with its exact name, all three problems are reported in one run rather than one per run, and a name differing only in case is pointed out, because names are case sensitive and that is the mistake everyone makes. Notes and limitations - The script must run on the chart the lines are drawn on. - Prices are read once, at run time. Moving a line afterwards does not move the order or its stops. - The stop and target ride on the order ticket itself, so they are attached from the moment of the fill - there is no unprotected window and nothing needs to keep running after the script ends. - Stop, target and entry distances are all checked against the broker's minimum stop distance before sending, with the numbers printed on refusal. - The risk figure assumes the stop fills at its price. A gap or slippage through the stop loses more; no script can promise otherwise. - The order is GTC: no expiry, survives restarts, until filled or deleted. - One bracket per run. For staged entries across a zone, see the Scale In Ladder script.
Script · MT4 · v1.0 · Free
About Bracket From Three Lines
Bracket From Three Lines 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 8 settings, such as Entry line name, Stop line name and Target line name. MQL source code included.
Files in the download: BracketFromLines.ex4, BracketFromLines.mq4, BracketFromLines.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 |
|---|---|---|
| Entry line name | entry | Name of the entry line |
| Stop line name | stop | Name of the stop loss line |
| Target line name | target | Name of the take profit line |
| Risk percent | 1.0 | Risk, percent of equity, if the stop is hit |
| Magic | 0 | Magic number written on the order |
| Max retries | 5 | Attempts before giving up |
| Retry wait ms | 500 | Pause between attempts, milliseconds |
| Confirm first | true | Ask for confirmation before placing |
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: Volume · Pending Orders · Risk & Lot Size · MT4 Script · MQL4 Source Code