Chart Helper FxMath_Harmonic_Hunter_Helper(MT5)
Attach the Helper to the chart of a symbol you want to trade. It finds the current harmonic pattern on that chart, draws it with all trade levels, lets you open Instant / Stop / Limit orders via CTrade, and then manages the position with partial close + breakeven. It also includes optional fake-pattern filters and an in-EA logistic-regression signal filter, all controllable from an on-chart Settings panel.
#Overview
The Helper is the execution half of the suite. On attach it:
1. Reads the Scanner's settings
Parses <AccountLogin>.Pouya from MQL5\Files\ — accuracy, depth range, scan window, pattern age, TP level, trading mode, magic number, comment, colors.
2. Loads the ML model
ML_Load() restores previously trained logistic weights (Group B filter).
3. Scans & draws immediately
Scan() runs right away in OnInit and then on a 2-second timer — so patterns appear even when the market is closed (no ticks).
4. Trains the ML filter
ML_Collect() + ML_Refresh() build a training set from the chart's own history (only when ML is enabled).
OnTick() never
fires. It now uses EventSetTimer(2) + OnTimer() + an immediate
Scan() in OnInit (and EventKillTimer() in
OnDeinit) — the pattern stays drawn and fresh without a single tick.
#Pattern display
When a pattern is found, the Helper draws (DrawBestPattern):
- Triangles for the XAB and BCD legs (in
Pattern_Body_Color). - X–A–B–C–D labels at the pivot points.
- Ratio labels (XB / AC / BD / XD) on dashed connector lines.
- AC channel with parallel rays projected to the current bar.
- Trade levels as horizontal lines: Open Price, TP1, TP2, TP3, SL (see below) with value labels.
- ATR badge (cyan) when ATR mode is active:
ATR(14) SL 2.0x TP1 4.0x TP2 6.0x TP3 9.0x RR 1:2. - Filter badge with ✔/✘ verdicts for every enabled filter
(e.g.
✔Trend ✔RSI ✘S/R ML 78%). - Info labels top-left: Pattern, Open Type, OpenPrice, StopLoss, TakeProfit 1/2/3.
Flicker-free redraw
Objects use deterministic names and a signature guard
(g_lastPatternSig = "pattern|depth|p_x|p_d"). An unchanged pattern is not
deleted/redrawn on every tick — this fixed the old flicker from
ObjectsDeleteAll(0) + random object names every tick.
#Trade levels
| Level | Formula | Meaning |
|---|---|---|
| Open Price | D ± (0.238 × CD) / 2 | Entry — mid-way into the 23.8% retracement of CD |
| TP1 | D ± 0.38 × AD | 38% of the XA leg |
| TP2 | D ± 0.618 × AD | 61.8% of the XA leg |
| TP3 | D ± 0.786 × AD | 78.6% of the XA leg |
| Stop Loss | D ± 0.05 × CD | 5% beyond the CD leg |
Signs depend on direction: for a bullish pattern (D < C) add; for a
bearish pattern (D > C) subtract.
With SLTP_Use_ATR = true (read from .Pouya), the drawn lines
use ATR-based levels instead: SL = ATR × SLTP_ATR_SL_Mult and
TP1/2/3 = ATR × TP1/2/3_Mult, measured at the D point. A cyan badge shows the
multipliers and the R:R of the level selected by TakeProfit_Level.
#Trading panel ("Trading Options")
Clicking the red Trading Options button (top-right) toggles the panel:
| Control | Purpose |
|---|---|
| Lot | Fixed lot size edit box. |
| Risk | Risk % per trade — when > 0, money management overrides the fixed lot. |
| Instant Order | Opens immediately at market: Buy = Ask, Sell = Bid. |
| Stop Order | Places Buy Stop / Sell Stop at the pattern's Open Price. |
| Limit Order | Places Buy Limit / Sell Limit at the pattern's Open Price. |
All orders go through the CTrade class
(trade.Buy / Sell / BuyStop / SellStop / BuyLimit / SellLimit) with the
Scanner's magic number, the trade comment, SL/TP from the pattern and an expiry of
ExpirationTime_Candle candles (0 = GTC). Deviation is set to 20 points.
#Order types in detail
| Mode | Bullish pattern (TradeType=1) | Bearish pattern (TradeType=-1) | Entry price |
|---|---|---|---|
| 1 — Instant | trade.Buy @ Ask | trade.Sell @ Bid | Current market price |
| 2 — Stop | trade.BuyStop @ OpenPrice | trade.SellStop @ OpenPrice | Pattern Open Price (above market for BuyStop, below for SellStop) |
| 3 — Limit | trade.BuyLimit @ OpenPrice | trade.SellLimit @ OpenPrice | Pattern Open Price (below market for BuyLimit, above for SellLimit) |
BuyLimit makes
sense, while a BuyStop would only fill if price first pushes above. Choose the
mode that matches your expectation of the retracement.
#Position management
ManagePositions() runs on every tick/timer. It manages only positions on its
own chart symbol with the Scanner's MagicNumber, and each ticket only once
(tracked in g_managedTickets[]). When the price travels
BE_Ratio_Distance (default 0.6 = 60%) of the entry→TP distance:
| Action | Condition | Implementation |
|---|---|---|
| Breakeven | Breakeven_Enable | trade.PositionModify(ticket, entry + 10×point, TP) — only improves the existing SL. |
| Partial close | Close_Partial_Trade | trade.PositionClosePartial(ticket, closeVol) where closeVol = floor(volume × Close_Partial_Ratio / step) × step, clamped by min volume. |
progress = |price − open| / |tp − open|. The trigger defaults to 0.5 if
BE_Ratio_Distance ≤ 0, clamped to 1.0 max. A ticket is marked managed before
acting, so a failed order call retries next tick.
#Chart-side Settings panel
A compact panel (top-left, below the Studies buttons, Sett_X=20, Sett_Y=380)
controls all filter/ML settings directly on the chart — no F7 needed.
All objects use the Sett_ prefix so they never clash with pattern/trade objects.
| Row | Controls | Values |
|---|---|---|
| 1 | Trend ON/OFF + Per | EMA period (1–500) |
| 2 | RSI ON/OFF + Per + Zone | RSI period (2–100), zone (5–95) |
| 3 | S/R ON/OFF + Back + Pips | lookback (5–500), pips (0–1000) |
| 4 | Hide ON/OFF | hide pattern when any enabled filter fails |
| 5 | ML ON/OFF + Min% | min probability (1–99) |
| 6 | Train Bars / Look / MinN | training bars (200–5000), lookahead (5–200), min samples (5–200) |
| 7 | SL/TP mode Fibo/ATR + ATRPer + SL + TP1/2/3 | ATR period, SL/TP multipliers (defaults 2.0 / 4.0 / 6.0 / 9.0) |
| 8 | Retrain ML / Defaults | rebuild + retrain now / reset all to OFF |
- Buttons: green = ON, maroon = OFF. Edits apply on Enter or focus loss
(
CHARTEVENT_OBJECT_ENDEDIT). - Every change re-scans the chart instantly so the ✔/✘ badge and hidden-pattern behaviour update right away.
- Set the
Sett_Hideinput totrueto hide the panel and use F7 instead. - The
FLT_*/ML_*variables are runtime — the input defaults seed them, the panel updates them live.
#Fake-pattern filters — Group A (chart-side confirmation)
All default OFF, so the Helper behaves exactly as before until you enable
them. When a filter is on, the Helper draws a small ✔/✘ badge next to the
SL line (✔Trend ✔RSI ✘S/R …); with FLT_Hide=true a failed filter
hides the pattern entirely.
| Input | Default | Logic |
|---|---|---|
| FLT_Trend_Enable / FLT_Trend_Period | false / 50 | Bullish patterns need price above the EMA at D; bearish patterns below. Fakes often form against the trend. (EMA_Shift) |
| FLT_RSI_Enable / FLT_RSI_Period / FLT_RSI_Zone | false / 14 / 40 | Bullish D needs RSI ≤ zone (oversold confluence); bearish D needs RSI ≥ 100−zone (overbought). Zone clamped 10–90. (RSI_Shift) |
| FLT_SR_Enable / FLT_SR_Lookback / FLT_SR_Pips | false / 50 / 20 | D must sit within FLT_SR_Pips points of a previous swing high/low (S/R confluence; "mid-air" patterns = classic fakes). (SR_Distance) |
| FLT_Hide | false | false = just show ✔/✘ verdicts; true = skip drawing when any enabled filter fails. |
#Fake-pattern filters — Group B (logistic-regression "signal strength")
A lightweight logistic regression trained inside the Helper on this chart's own history — pure MQL5 math, no ONNX, no DLL.
Collect
ML_Collect() scans the last ML_TrainBars bars, finds historical harmonic setups with the same ZigZag engine (best-per-D-bar) and labels each by "did price reach TP1 within ML_Lookahead bars" (1/0). Memory is capped at 200 samples.
Train
ML_Train() runs 300 gradient-descent iterations on 6 weights (bias + 5 features: accuracy %, XB/AC/BD/XD ratios) with feature normalization to ~[−1,1]. Requires ≥ ML_MinSamples samples.
Persist
ML_Save() / ML_Load() store the weights in ML_File (Harmonic_ML.dat, per chart+timeframe). Re-trains at most every 6 hours.
Predict
Each new pattern gets a probability (0–100). The badge shows ML 78%; below ML_MinProb the badge turns red and (with FLT_Hide) the pattern is hidden.
| Input | Default | Description |
|---|---|---|
| ML_Enable | false | Master switch. |
| ML_TrainBars | 1000 | Historical bars scanned for training samples. |
| ML_Lookahead | 30 | Bars after D used to decide "did TP1 hit?" (label). |
| ML_MinProb | 50 | Hide patterns with predicted probability below this %. |
| ML_MinSamples | 20 | Minimum training samples before the model is used. |
| ML_File | "Harmonic_ML.dat" | Persistence file for the trained weights. |
ML % as a rough confluence score, not a
guarantee.
#Money management
- Fixed lot:
Lotsfrom the panel (clamped toMaximumLots = 1000). - Risk %: when
PercentageRisked > 0,riskPerTrade = balance × % / 100, converted to lots viacomputeMMFromRiskPerTrade(): tick-value/contract-size currency adjuster, volume-step snapping, min/max volume clamping, and a ×10 adjustment forCONTRACT_SIZE = 10000instruments.
#Input parameters
The Helper has very few real inputs — most settings come from the
.Pouya file, and the filter/ML settings are runtime variables (seeded by inputs
but changeable from the Settings panel). The search box filters by parameter name.
| Input | Type | Default | Description |
|---|---|---|---|
| Harmonic Settings | Group separator (the Scanner's accuracy/depth/age/TP settings are read from .Pouya at attach). | ||
| Sett_Hide | bool | false | true = hide the chart-side Settings panel (use F7 instead). |
| ZigZag_Window_Bars | int | 1000 | History window for the in-EA ZigZag cache. |
| FLT_Trend_Enable | bool | false | Group A — trend alignment filter (runtime; panel-toggleable). |
| FLT_Trend_Period | int | 50 | EMA period for the trend filter. |
| FLT_RSI_Enable | bool | false | Group A — RSI zone filter. |
| FLT_RSI_Period | int | 14 | RSI period. |
| FLT_RSI_Zone | double | 40 | Bullish D: RSI ≤ zone; bearish D: RSI ≥ 100−zone. |
| FLT_SR_Enable | bool | false | Group A — S/R proximity filter. |
| FLT_SR_Lookback | int | 50 | Bars back to search for the nearest swing level. |
| FLT_SR_Pips | double | 20 | Max distance (points) from D to the nearest swing. |
| FLT_Hide | bool | false | Hide the pattern entirely when any enabled filter fails. |
| ML_Enable | bool | false | Group B — master switch for the logistic-regression filter. |
| ML_TrainBars | int | 1000 | Historical bars scanned for training samples. |
| ML_Lookahead | int | 30 | Bars after D for the "did TP1 hit?" label. |
| ML_MinProb | double | 50 | Hide patterns below this predicted probability %. |
| ML_MinSamples | int | 20 | Minimum training samples before the model is used. |
| ML_File | string | "Harmonic_ML.dat" | Persistence file for the trained weights. |
Settings read from .Pouya (not inputs)
| Key | Used for |
|---|---|
| accuracy | Pattern_Accuracy (ratio tolerance) |
| Maximum_Market_Bar_Scan / Minimum_Market_Depth / Maximun_Market_Depth | Scan window + ZigZag depth range |
| Maximum_Pattern_Age | Age filter (D point newer than N candles) |
| TakeProfit_Level | Which TP (1/2/3) the orders use |
| TradeComment / MagicNumber | CTrade comment + magic |
| ExpirationTime_Candle | Pending-order expiry in candles |
| Close_Partial_Trade / Close_Partial_Ratio | Partial close management |
| Breakeven_Enable / BE_Ratio_Distance | Breakeven management + trigger |
| SLTP_Use_ATR / SLTP_ATR_Period / SLTP_ATR_SL_Mult / SLTP_TP1_Mult / SLTP_TP2_Mult / SLTP_TP3_Mult | ATR-based SL/TP levels |
| Helper_Text_Color / Pattern_Body_Color | Chart label + pattern colors |
#SL/TP selection & .Pouya sync
TakeProfit_Level (from the Scanner) selects the active TP:
1 → TP1 (38%), 2 → TP2 (61.8%), 3 → TP3 (78.6%) of
XA. In ATR mode the same level picks the corresponding ATR multiplier. The Helper reads
.Pouya once at attach; changing Scanner settings while the
Helper runs requires re-attaching the Helper — except the filter/ML settings, which are
live runtime variables from the Settings panel.
#Extra studies (optional buttons)
The More Studies button (top-left) reveals legacy analysis tools:
- BC/AB Filter — shows the current AC ratio (BC/AB); a ratio < 1.0 gets a green ✔ Wingdings check.
- Fibo Time Filter — Fibonacci time-zone fan on XB and AC
(
FiboTime_XB,FiboTime_AC) with ratio-based confirmation checks (1.58–2.63 → green ✔). - AC Filter / XB Filter buttons toggling those fans.
These are auxiliary drawing helpers — they don't open orders.
#Workflow
1. Attach the Scanner first
Attach/refresh the Scanner so <login>.Pouya contains the settings you want.
2. Attach the Helper
On the chart of the symbol you want to trade (or via the Scanner's View / Open All Charts buttons).
3. Check the pattern & badges
Verify the drawn pattern, trade levels, and any ✔/✘ / ML badges. Optionally enable filters in the Settings panel.
4. Set risk & open
Open Trading Options, set Lot or Risk %, and click Instant / Stop / Limit.
5. Let it manage
The Helper handles partial close + breakeven automatically per the Scanner's Trading Mode.
#Known limitations
- Settings from
.Pouyaare read once at attach — the Helper doesn't watch the file for changes (except the filter/ML runtime settings). - Wolfe Waves disabled (commented call site
//if(valid==0)WolfeScan(dep,point);). - Custom CSV patterns disabled (
ReadCSV()commented out inOnInit). - License check bypassed (
License=falsein the Helper, validation code commented). - WinInet
httpGET(version check on attach) requires Allow DLL imports. - ML features age/ATR are stored but not used in the linear predictor (stability on small samples).