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.

File: FxMath_Harmonic_Hunter_Helper(MT5).mq5/.ex5 2-second timer (works on closed market) CTrade-based order execution In-EA ML filter (no DLL/ONNX) Reads <login>.Pouya from Scanner

#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).

ℹ️ Tickless operation The original Helper did nothing on closed-market pairs because 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):

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

LevelFormulaMeaning
Open PriceD ± (0.238 × CD) / 2Entry — mid-way into the 23.8% retracement of CD
TP1D ± 0.38 × AD38% of the XA leg
TP2D ± 0.618 × AD61.8% of the XA leg
TP3D ± 0.786 × AD78.6% of the XA leg
Stop LossD ± 0.05 × CD5% 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:

ControlPurpose
LotFixed lot size edit box.
RiskRisk % per trade — when > 0, money management overrides the fixed lot.
Instant OrderOpens immediately at market: Buy = Ask, Sell = Bid.
Stop OrderPlaces Buy Stop / Sell Stop at the pattern's Open Price.
Limit OrderPlaces 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

ModeBullish pattern (TradeType=1)Bearish pattern (TradeType=-1)Entry price
1 — Instanttrade.Buy @ Asktrade.Sell @ BidCurrent market price
2 — Stoptrade.BuyStop @ OpenPricetrade.SellStop @ OpenPricePattern Open Price (above market for BuyStop, below for SellStop)
3 — Limittrade.BuyLimit @ OpenPricetrade.SellLimit @ OpenPricePattern Open Price (below market for BuyLimit, above for SellLimit)
⚠️ Direction semantics The entry level sits at the 23.8% retracement of CD. For a bullish pattern the price is expected to retrace down to OpenPrice first — hence 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:

ActionConditionImplementation
BreakevenBreakeven_Enabletrade.PositionModify(ticket, entry + 10×point, TP) — only improves the existing SL.
Partial closeClose_Partial_Tradetrade.PositionClosePartial(ticket, closeVol) where closeVol = floor(volume × Close_Partial_Ratio / step) × step, clamped by min volume.
ℹ️ Progress metric 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.

RowControlsValues
1Trend ON/OFF + PerEMA period (1–500)
2RSI ON/OFF + Per + ZoneRSI period (2–100), zone (5–95)
3S/R ON/OFF + Back + Pipslookback (5–500), pips (0–1000)
4Hide ON/OFFhide pattern when any enabled filter fails
5ML ON/OFF + Min%min probability (1–99)
6Train Bars / Look / MinNtraining bars (200–5000), lookahead (5–200), min samples (5–200)
7SL/TP mode Fibo/ATR + ATRPer + SL + TP1/2/3ATR period, SL/TP multipliers (defaults 2.0 / 4.0 / 6.0 / 9.0)
8Retrain ML / Defaultsrebuild + retrain now / reset all to OFF

#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.

InputDefaultLogic
FLT_Trend_Enable / FLT_Trend_Periodfalse / 50Bullish 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_Zonefalse / 14 / 40Bullish 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_Pipsfalse / 50 / 20D must sit within FLT_SR_Pips points of a previous swing high/low (S/R confluence; "mid-air" patterns = classic fakes). (SR_Distance)
FLT_Hidefalsefalse = 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.

InputDefaultDescription
ML_EnablefalseMaster switch.
ML_TrainBars1000Historical bars scanned for training samples.
ML_Lookahead30Bars after D used to decide "did TP1 hit?" (label).
ML_MinProb50Hide patterns with predicted probability below this %.
ML_MinSamples20Minimum training samples before the model is used.
ML_File"Harmonic_ML.dat"Persistence file for the trained weights.
⚠️ Statistical caution The model is trained on past setups on the same chart/timeframe. Small samples can overfit; the age/ATR features are stored but intentionally excluded from the linear predictor for stability. Treat ML % as a rough confluence score, not a guarantee.

#Money management

#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.

InputTypeDefaultDescription
Harmonic SettingsGroup separator (the Scanner's accuracy/depth/age/TP settings are read from .Pouya at attach).
Sett_Hideboolfalsetrue = hide the chart-side Settings panel (use F7 instead).
ZigZag_Window_Barsint1000History window for the in-EA ZigZag cache.
FLT_Trend_EnableboolfalseGroup A — trend alignment filter (runtime; panel-toggleable).
FLT_Trend_Periodint50EMA period for the trend filter.
FLT_RSI_EnableboolfalseGroup A — RSI zone filter.
FLT_RSI_Periodint14RSI period.
FLT_RSI_Zonedouble40Bullish D: RSI ≤ zone; bearish D: RSI ≥ 100−zone.
FLT_SR_EnableboolfalseGroup A — S/R proximity filter.
FLT_SR_Lookbackint50Bars back to search for the nearest swing level.
FLT_SR_Pipsdouble20Max distance (points) from D to the nearest swing.
FLT_HideboolfalseHide the pattern entirely when any enabled filter fails.
ML_EnableboolfalseGroup B — master switch for the logistic-regression filter.
ML_TrainBarsint1000Historical bars scanned for training samples.
ML_Lookaheadint30Bars after D for the "did TP1 hit?" label.
ML_MinProbdouble50Hide patterns below this predicted probability %.
ML_MinSamplesint20Minimum training samples before the model is used.
ML_Filestring"Harmonic_ML.dat"Persistence file for the trained weights.

Settings read from .Pouya (not inputs)

KeyUsed for
accuracyPattern_Accuracy (ratio tolerance)
Maximum_Market_Bar_Scan / Minimum_Market_Depth / Maximun_Market_DepthScan window + ZigZag depth range
Maximum_Pattern_AgeAge filter (D point newer than N candles)
TakeProfit_LevelWhich TP (1/2/3) the orders use
TradeComment / MagicNumberCTrade comment + magic
ExpirationTime_CandlePending-order expiry in candles
Close_Partial_Trade / Close_Partial_RatioPartial close management
Breakeven_Enable / BE_Ratio_DistanceBreakeven management + trigger
SLTP_Use_ATR / SLTP_ATR_Period / SLTP_ATR_SL_Mult / SLTP_TP1_Mult / SLTP_TP2_Mult / SLTP_TP3_MultATR-based SL/TP levels
Helper_Text_Color / Pattern_Body_ColorChart 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:

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