Loading…

Price Ruler Between Two Lines

MetaTrader has no built-in tool that draws two points a trader can drag by hand and then re-read on demand. The Crosshair only reads one point at a time, and the built-in Fibonacci and trend-line tools carry properties that measurement is not really their job. What is actually wanted, most of the time, is simpler than any of them: two markers you can place, move around while you think, and then ask "what is the distance between these two, exactly". This script gets there with a plain two-run pattern instead of pretending to be a custom chart tool with mouse-drag handling built in, which the language does not give a script direct access to on either platform. The first run creates two ordinary vertical-line objects, named ruler_a and ruler_b, positioned at the one-third and two-thirds points of whatever range is currently visible on the chart. They are left selectable, so from that point on they behave exactly like any line you drew yourself - click one, drag it to where you want it measured from, drag the other to where you want it measured to. The second run finds both lines still on the chart, reads their current position rather than the position they were created at, and does the measuring. That is the entire trick: the objects are not special, they are just two lines the script remembers the names of, and it is the run-again step that turns "draw two lines" into "measure between two points". Running the script again after that re-measures from wherever the lines are now, so you can nudge one and immediately re-run to see the new figure. The measurement itself uses the nearest real bar to each line, found with iBarShift, rather than the raw pixel position, because price and time only mean anything at a bar close on the chart's own timeframe. Bars between, elapsed time, signed price change, pips, percent change and the high-low range across the whole span are all reported together, both in the Experts log and as a short text label drawn on the chart next to the second line, so the number is there to look at without switching to the log tab. Notes and limitations - Measurement is only as precise as bar-close granularity on the chart's current timeframe. Switch to a lower timeframe before placing the lines if you want a finer reading; the ruler does not resample across timeframes. - Percent change divides by the earlier of the two closes. That close being exactly zero would make the percentage undefined, which the script guards against, but it is not a situation any real price feed produces. - The script owns exactly three chart objects - ruler_a, ruler_b and the result label - and never touches anything else you have drawn. - If a line is dragged off the loaded history (further back than the chart has data for) the second run cannot match it to a bar and reports that plainly rather than guessing. - Only one ruler is tracked at a time on a given chart, since the object names are fixed. Running it on several charts at once works fine - each chart keeps its own pair of lines.

Script · MT5 · v1.0 · Free

About Price Ruler Between Two Lines

Price Ruler Between Two Lines is a script for MetaTrader 5. It can alert you with a pop-up, sound, email or push message. It has 1 setting, such as Reset. MQL source code included.

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

Settings

SettingDefaultWhat it does
ResetfalseRemove the ruler and start fresh on the next run

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

Download the PDF guide

Tags: Fibonacci · Trend · Alerts · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria