Loading…

Weighted Price Composites

Every strategy that wants "typical price" or "weighted close" ends up writing the same three-line formula in a dozen different files, and a genuinely custom weighted blend - for example, a trend filter that wants the close weighted five times heavier than the wicks - is usually skipped entirely because it means yet another formula to keep consistent with the rest. This library collects the four common composite kinds behind one enum and one function, PriceCompositeGet(), plus a separate PriceCompositeGetCustom() for an arbitrary caller-supplied weighting of Open/High/Low/Close. Weights passed to the custom function do not need to sum to 1 - they are normalised internally, so "2, 1, 1, 4" and "0.25, 0.125, 0.125, 0.5" produce the identical result. A non-positive weight sum (all zero, or a caller mistake) falls back to the plain typical price rather than dividing by zero. Notes and limitations - All four built-in kinds and the custom blend read historical O/H/L/C via iOpen/iHigh/iLow/iClose - they do not access tick-level Bid/Ask, so shift 0 reflects the current, still-forming bar exactly the way any other bar-based indicator does. - The custom blend's normalisation only guards against a non-positive weight SUM. Passing one large weight and three zero weights is valid and simply returns that single price component - it is not an error. - No smoothing or averaging across bars is applied anywhere in this library; every function reads exactly one bar's O/H/L/C. Combine with a moving-average call if a smoothed composite is wanted.

Script · MT4 · v1.0 · Free

About Weighted Price Composites

Weighted Price Composites is a script for MetaTrader 4. It has 5 settings, such as Bars to show, Weight open and Weight high. MQL source code included.

Files in the download: WeightedPriceComposites.mqh, WeightedPriceComposites.txt, WeightedPriceCompositesDemo.mq4.

Settings

SettingDefaultWhat it does
Bars to show5How many recent closed bars to print
Weight open1.0Custom blend: weight on Open
Weight high1.0Custom blend: weight on High
Weight low1.0Custom blend: weight on Low
Weight close5.0Custom blend: weight on Close (heavy by default)

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

MQL4 & MQL5 scripts · PolyMaria