Loading…

Chart Object Alignment Cleaner

A trendline dragged onto a chart during a fast market rarely lands exactly on a bar's open time or a round price. It is close enough to read, but a pixel or two off the bar it was meant to mark, and a rectangle drawn to box a range ends up with edges at prices like 1.08734 instead of 1.08700. None of this affects the analysis, but it makes a chart look sloppy, and it makes objects harder to compare against each other by eye. This script snaps both coordinates of every eligible object: time anchors move to the exact open time of the nearest bar, and price anchors round to the nearest multiple of a configurable step in points. The two snaps are independent switches, so a chart can be time-aligned only, price-aligned only, or both. The detail that matters is that MT4 objects do not all have the same number of anchor points. A vertical line has one, a trendline or rectangle has two, and a Gann fan or time-based Fibonacci tool has three. A script that assumes two points for everything either misses the third point on the objects that have one, or wastes calls probing points that do not exist on the objects that only have one or two. This script looks up the correct anchor count per object type before touching anything, and screen- anchored objects with no time or price at all - text labels, buttons, panel backgrounds - are recognised and skipped outright rather than having meaningless coordinates rewritten. Notes and limitations - Only objects with time/price anchor points are affected. Text labels, buttons, edit boxes and other screen-anchored objects are left exactly as they are, because they have no chart coordinate to snap. - The time snap resolves to bars currently loaded in the chart's history. An anchor pointing further back than the loaded history is left unchanged rather than snapped to the oldest available bar. - Snapping is destructive to the original hand-drawn position - there is no undo beyond the terminal's own object history, so review the count in the confirmation prompt before proceeding on a chart with important manual analysis. - Snapping does not change an object's colour, style or width, only its time and price coordinates. - Running the script twice in a row on an already-snapped chart is safe and simply reports the same (unchanged) positions again.

Script · MT4 · v1.0 · Free

About Chart Object Alignment Cleaner

Chart Object Alignment Cleaner is a script for MetaTrader 4. It draws buy and sell arrows on the chart and can alert you with a pop-up, sound, email or push message. It has 4 settings, such as Price step points, Snap time to bar and Name prefix only. MQL source code included.

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

Settings

SettingDefaultWhat it does
Price step points100Snap price to the nearest multiple of this many points (0 = leave price alone)
Snap time to bartrueSnap every time anchor to the nearest bar's exact open time
Name prefix onlyOnly touch objects whose name starts with this (blank = every object)
Confirm firsttrueAsk for confirmation before moving anything

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

Download the PDF guide

Tags: Grid · Fibonacci · Trend · Buy/Sell Arrows · Alerts · MT4 Script · MQL4 Source Code

MQL4 & MQL5 scripts · PolyMaria