Loading…

Order At Drawn Line

The plan is on the chart: a horizontal line at the price where the trade should happen. Getting that price into an order ticket by hand means retyping five digits, and a transposed digit in a pending order is a mistake you discover only when it fills. This script reads the line and places the order at its exact price. You choose the direction; the script derives the type from the geometry. A buy above the ask can only be a buy stop, a buy below it only a buy limit, and the sell cases mirror against the bid. Deriving the type from the drawing removes the classic ticket error of picking "limit" from a dropdown while the price sits on the stop side, which the server either rejects or, worse, quietly accepts as a different trade than intended. The type can be forced through an input, but a forced type that contradicts the geometry is refused with an explanation, never silently corrected. Two details separate this from the naive version. A hand-drawn line almost never sits exactly on the broker's price grid - the drawn value is an arbitrary double like 1.084537 on an instrument that ticks in 0.00001 - so the price is snapped to the tick size before it is sent; unsnapped prices are a stock source of "invalid price" rejections. And when the named line does not exist, the script lists every horizontal line on the chart in the Experts log with its name and price, because object names are case sensitive and invisible on the chart. A line named "Entry" when the script wants "entry" is flagged explicitly as differing only in case. The line's distance from the market is checked against the broker's minimum stop distance before anything is sent, and an optional stop loss and take profit, in pips from the entry, can ride along on the same ticket. Notes and limitations - The script must run on the chart the line is drawn on. Objects do not exist across charts. - One line, one order, one run. Run it again for a second order. - The line's price is read once, at run time. Moving the line afterwards moves nothing - the order does not follow it. - A line inside the broker's minimum stop distance from the market is refused, with both distances printed. Move the line or trade at market. - The order is GTC: it has no expiry and survives disconnects and restarts until filled or deleted. - Object names are case sensitive. The log's "differs only in case" hint exists because that is the mistake everyone makes.

Script · MT4 · v1.0 · Free

About Order At Drawn Line

Order At Drawn Line is an expert advisor (trading robot) for MetaTrader 4. It places pending buy/sell stop or limit orders. It has 10 settings, such as Line name, Direction and Pending mode. MQL source code included.

Files in the download: OrderAtDrawnLine.ex4, OrderAtDrawnLine.mq4, OrderAtDrawnLine.txt.

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

Settings

SettingDefaultWhat it does
Line nameentryName of the horizontal line
DirectionDIR_BUYTrade direction
Pending modePENDING_AUTOPending order type
Lots0.10Volume, in lots
Stop loss pips0Stop loss distance, pips (0 = none)
Take profit pips0Take profit distance, pips (0 = none)
Magic0Magic number written on the order
Max retries5Attempts before giving up
Retry wait ms500Pause between attempts, milliseconds
Confirm firsttrueAsk for confirmation before placing

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: Pending Orders · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria