Htf Confirmation Engine
Multi-timeframe confirmation is a standard filter: only take an M15 signal if H1 and H4 agree with its direction. The standard way people implement the HTF read is iBarShift(symbol, timeframe, TimeCurrent(), false) followed by reading shift 0 of that timeframe. That is wrong on almost every tick, because shift 0 is the higher timeframe's CURRENT bar - it has not finished forming. Its open is fixed but its high, low and close keep moving with every tick, including the very tick evaluating the rule. A confirmation rule built on that value is not confirming against anything settled; it silently changes its own answer as price moves, which defeats the point of requiring agreement in the first place and is indistinguishable from ordinary indicator repainting once it feeds a trading decision. This header fixes the read, not the rule logic. GetLastClosedHtfShift is the single function every rule evaluator in this file routes through: it calls iBarShift as usual, and whenever that returns shift 0 - which is most of the time, since "now" falls inside the current bar on nearly every tick - it bumps the result to shift 1, the most recently CLOSED bar. No other function in this header reads higher-timeframe Open/High/Low/Close or an MA value directly; they all go through this one shift resolver first, so there is exactly one place in the file where the lookahead fix can go wrong, and exactly one place to check when auditing a caller's behaviour. Rules themselves are declarative: an array of SHtfRule structs, each naming a timeframe and a rule type (bullish/bearish closed candle, closed price above or below an MA, or MA rising/falling versus one bar earlier). CountAgreeingRules walks the array and reports how many rules agree, plus a line of readable reasoning per rule - built for a trading program that wants "how many of my five HTF filters currently agree" as a plain number, not a boolean AND that tells you nothing about which filter is the holdout. Notes and limitations - This header never sends an order and never draws on the chart - it only answers "does this closed-bar rule agree", so the caller decides what to do with the count. - GetLastClosedHtfShift depends on the requested timeframe's history already being loaded for the symbol. On a freshly attached higher timeframe that has not synchronised yet, it returns -1 rather than guessing - callers should treat that as "not ready" and skip the rule that tick, not as "rule failed". - The MA-slope rule compares the last closed bar's MA reading against the MA reading one closed bar earlier; it says nothing about the trend beyond those two points and is not a substitute for a proper trend-strength measure. - Indicators here never repaint by construction, since every read is anchored to a fixed, already-closed bar shift rather than a live one.
Script · MT5 · v1.0 · Free
About Htf Confirmation Engine
Htf Confirmation Engine is a script for MetaTrader 5 based on Moving Average. It has 1 setting, such as Ma period. MQL source code included.
Files in the download: HtfConfirmationEngine.mq5.mqh, HtfConfirmationEngine.txt, HtfConfirmationEngineDemo.ex5, HtfConfirmationEngineDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Ma period | 20 | Moving average period used by the price-vs-MA and slope rules |
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: Moving Average · Multi-Timeframe (MTF) · Buy/Sell Arrows · MT5 Script · MQL5 Source Code