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 · MT5 · v1.0 · Free
About Weighted Price Composites
Weighted Price Composites is a script for MetaTrader 5. It has 5 settings, such as Bars to show, Weight open and Weight high. MQL source code included.
Files in the download: WeightedPriceComposites.mq5.mqh, WeightedPriceComposites.txt, WeightedPriceCompositesDemo.ex5, WeightedPriceCompositesDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Bars to show | 5 | How many recent closed bars to print |
| Weight open | 1.0 | Custom blend: weight on Open |
| Weight high | 1.0 | Custom blend: weight on High |
| Weight low | 1.0 | Custom blend: weight on Low |
| Weight close | 5.0 | Custom blend: weight on Close (heavy by default) |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Trend · MT5 Script · MQL5 Source Code