Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Market Structure Onnx - MetaTrader 5 Expert | MT5 EA Download - MetaTrader 5 Resources

author EAcpu | 5 reads | 0 comments |

Market Structure Onnx - expert for MetaTrader 5

Market Structure Onnx - expert for MetaTrader 5

Market Structure Onnx - expert for MetaTrader 5

Market Structure Onnx - expert for MetaTrader 5

The strategy combines machine learning-based market structure classification and rules-based trade execution .
The ONNX model is used to classify current market structures, while classic technical analysis (moving average trend filters, Fibonacci retracements, ATR and risk-reward rules) is used to manage entries, exits and risk.

The system is designed to:

Trade only at pullback levels that make structural sense

Avoid overtrading by allowing only one active trade or pending order

Using probabilistic confidence filtering from AI models

Apply for risk-reward based trailing stop loss management

The ONNX model (market_struct.onnx) is loaded during initialization.
On each new bar, the model predicts the current state of the market structure .

The model receives six normalized features:

Momentum Change <br/>The price difference between the current closing price and the closing price 5 bars ago, normalized by ATR.

Distance to recent swing high <br/>The difference between the high of the last 50 bars and the current closing price, normalized by ATR.

Distance from recent swing low <br/>The difference between the current close and the lowest price of the last 50 bars (normalized by ATR).

Relative quote volume <br/>The current quote volume is compared to the average quote volume of the last 20 bars.

Candle Body Strength <br/>The difference between the closing price and the opening price, normalized by ATR.

Temporal characteristics (hour of day)
Intraday conversational behavior was coded.

These features allow the model to infer trend strength, retracement depth, volatility, volume context, and trade timing .

ONNX model output:

A forecast label represents a market structural state (e.g., higher high, higher low, lower high, lower low)

a probability score for the predicted class

Consider trading signals only if valid :

Prediction confidence is above a defined threshold (default 0.65)

The signal is consistent with the higher timeframe trend filter

This ensures that low confidence or noisy signals are ignored .

A 50-period simple moving average (SMA) is used as a directional filter:

Bullish Bias : Price Above SMA

Bearish Bias : Price Below SMA

The direction of trade is subject to the following restrictions:

Bullish market structure signals are allowed to occur only in bullish trends

Bearish market structure signals are allowed to occur only in bearish trends

This prevents counter-trend entries.

This strategy does not use market orders, but instead uses pending limit orders at Fibonacci retracement levels.

Recent swing highs and swing lows are scanned for historical highs and lows using a pivot-based approach .

Entry points are placed at predefined Fibonacci retracement levels (default 61.8% )

A pullback within this target's efficient market structure , not a breakout

Buy Limit in Bullish Cases

Sell ​​Limit in Bearish Case

Each pending order has:

Stop loss beyond structural failure level

Based on fixed profit risk reward ratio (default 1:2)

Avoid order expiration time

This policy enforces strict exposure controls:

Only one open position or one pending order

No stacking or martingale behavior

Stop loss is always defined on entry

Risks are structurally limited by:

market structure failure

ATR-Normalized distance

Once a position is active, a risk-reward based trailing stop is applied:

Tracking is activated after the price reaches a predefined fraction of the TP distance

The stop loss gradually moves towards breakeven or even higher.

The tracking logic for buy and sell positions is symmetrical

protect some profits

Allow winner to extend

Avoid premature stops due to noise

When creating a trading setup:

A Fibonacci object is plotted on the chart

The object will be automatically deleted once all trades and pending orders have been cleared

This helps visually confirm:

market structure

Retracement validity

All in all, the strategy follows a hybrid AI + rules-based approach :

AI classifies market structures using standardized context-aware capabilities

High confidence forecasts filtered by trend direction

Trades are only executed on Fibonacci retracements within the structure

Control risk with fixed rates of return and structural stop-loss settings

Dynamically manage profits using RR-based trailing stops

The result is a disciplined, structure-driven trading system that uses artificial intelligence for decision support rather than blind automation.


Attachment download

📎 market_structure.onnx (4522.58 KB)

📎 MarketStructure.mq5 (10.04 KB)

Source: MQL5 #68535

Verification code Refresh