Loading…

Market Profile Builder

A market profile needs a price histogram whose range is not known in advance - the session's eventual high and low only exist once the session is over - but "developing" is the entire point of a profile used for live trading: it has to be correct after every bar, not just at the close. Both MQL4 and MQL5 only allow the LEFTMOST dimension of a native array to be dynamic, so a growable 2D price/volume grid cannot be declared directly in either language. This header works around that with a struct-of-dynamic-arrays: SMarketProfile owns its own price-bin volume and touch-count arrays and grows them at either end as new bars arrive, which is exactly the pattern the array rules push toward for any genuinely ragged, size-unknown-in-advance 2D data on either platform. Running several independent profiles side by side - one per session, one per symbol - is just an array of SMarketProfile values, each with its own bin range. Without a tick-by-tick feed, no MT4 or MT5 program can know exactly where inside a bar's range price actually traded most. This header uses the same honestly-labelled approximation every bar-based profile tool uses: each bar's volume is spread evenly across every price bin its high-low range touches. It is an approximation, not a claim of tick-level accuracy, and the .txt says so plainly rather than pretending otherwise. The value area calculation follows the standard algorithm: starting from the point of control, it expands one bin at a time toward whichever side currently holds more volume just outside the band, until the accumulated volume reaches the target percentage (70% by convention). This keeps the value area contiguous around the point of control, rather than picking the highest-volume bins wherever in the range they happen to fall. Both headers are self-contained. No dependencies, no DLLs. Notes and limitations - Intrabar volume distribution is an approximation (even volume spread across the bar's range), not tick-accurate. It is the standard technique for any bar-based profile tool without a full tick history feed, but it should not be presented as replaying exactly where price traded within a bar. - "Volume" here is tick volume (iVolume on MQL4, iTickVolume on MQL5) - on most retail forex feeds this is not real traded contract volume. Read the broker's own documentation before treating profile shape as a genuine order-flow signal rather than an activity proxy. - Bin growth at the low end is an O(bins) shift-and-copy, not O(1). For the bin counts a realistic session produces (dozens to a few hundred) this is not measurable; it would matter for an unreasonably fine bin size run over a very wide range. - The value area algorithm assumes a single, sensible point of control. On a profile with multiple separated volume clusters of similar size, the 70% value area can still span across a thin middle bin - this matches how every standard market profile implementation behaves, not a bug specific to this header. - No money is at risk in either demo. Both read historical bar data only and never send a trade request.

Script · MT5 · v1.0 · Free

About Market Profile Builder

Market Profile Builder is a script for MetaTrader 5. It has 2 settings, such as Bars to profile and Bin size points. MQL source code included.

Files in the download: MarketProfileBuilder.mq5.mqh, MarketProfileBuilder.txt, MarketProfileBuilderDemo.ex5, MarketProfileBuilderDemo.mq5.

Settings

SettingDefaultWhat it does
Bars to profile48How many recent completed bars to feed into the profile
Bin size points50Bin width in broker points

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: Volume · Trading Sessions · MT5 Script · MQL5 Source Code

MQL4 & MQL5 scripts · PolyMaria