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

Sideways Martingale - MetaTrader 5 Expert - MT4/MT5 Resources

author EAcpu | 4 reads | 0 comments |

Sideways Martingale - expert for MetaTrader 5

Sideways Martingale - expert for MetaTrader 5

Sideways Martingale - expert for MetaTrader 5

Sideways Martingale - expert for MetaTrader 5

Sideways Martingale - expert for MetaTrader 5

Horizontal Martingale is an EA designed to trade sideways (range-bound) markets using the Martingale recovery strategy , enhanced with an AI-based trend detector implemented through an ONNX model .

EA combines:

AI trend classification (sideways/bullish/bearish)

Envelope indicator for range-based entries

Controlled martingale position scaling

Profit based basket closing

Margin based emergency stop

The core idea is:

Only trade when the market is statistically classified as moving sideways and avoid adding to martingale positions when a strong trend is detected.

The ONNX model returns:

Predicted labels (not used directly)

Probability vector three probabilities :

These probabilities are extracted as:

EA provides 9 engineering functions into the ONNX model:

These features allow AI model detection:

market fluctuations

Time-based behavior patterns

price structure behavior

Consider a market sideways when:

IfInpAISidewayThreshold = 0.70

A confidence level of at least 70% is then required to classify the market as moving sideways

👉No new transaction will be opened unless this condition is met

The EA uses envelopes to detect range extremes.

Price hits or breaks the lower envelope

Artificial Intelligence Confirms Sideways Markets

Open a buying position

Price hits or breaks the upper envelope

Artificial Intelligence Confirms Sideways Markets

Open a selling position

💡 This ensures that trades are conducted only in extreme ranges and under non-trending conditions.

When a position already exists, the EA applies distance-based martingale :

New positions will only be opened when the price deviates from the defined spread

Use multiplier (LotMultiplier) to increase lot size

The maximum number of trades is limited (MaxTradesInSeries)

This is a key risk control mechanism .

Before adding a new martingale position, the EA checks:

If the AI ​​detects a strong opposite trend

and confidence exceeds InpAISafetyThreshold

Martingale expansion has stopped

Martingale during a strong breakout

Deep retracement caused by trend continuation

The EA monitors the floating profit total for all positions:

if (total profit $>= profit target $)

All positions have been closed

The Martingale series has been reset

EA waits for new sideways settings

This approach treats all positions as a basket of trades .

If equity drawdown exceeds the specified percentage:

All positions are closed immediately

Prevent margin calls


Attachment download

📎 trend_detector.onnx (6444.66 KB)

📎 SidewaysMartingale.mq5 (8.88 KB)

Source: MQL5 #68537

Verification code Refresh