Z2 Multi Fractal Formation and Breakout
- 专家
- 版本: 1.4
- 更新: 2 八月 2026
- 激活: 10
This EA is a highly structured price-action algorithmic trading framework designed to demonstrate automated fractal execution mechanics. Instead of relying purely on lagging indicators, it is programmed to systematically map and react to structural market swings (Support and Resistance levels).
HOW IT OPERATES:
The algorithm continuously maps the market structure and evaluates conditions through a multi-layered analysis before making a simulated or trading decision. It looks for a strict alignment of your customized settings:
-
Price Action Trigger: Operates via two distinct engines. It is programmed to either enter the market the moment a new structural Fractal is confirmed (Formation Mode), or patiently wait for the price to aggressively break beyond a previously established fractal zone (Breakout Mode).
-
Trend Confirmation: Evaluates the fractal trigger against up to three customizable Moving Averages (EMAs). (Can be entirely disabled to transform the EA into a 'Pure Fractal Trader').
-
Momentum & Volatility Filters: Checks MACD, ADX, and ATR to observe if the market is too flat or dangerously chaotic.
-
Execution Safety: Aims to verify if the live spread is within your allowed maximum limit before attempting to send any request to the broker's server.
If the technical filters and safety parameters align at the exact moment of a valid fractal event, the EA attempts to execute the trade using a mathematically calculated lot size that targets your specified risk percentage.
KEY FEATURES:
-
Dual Fractal Engines: Allows you to freely switch between Breakout and Formation logic, complete with an "Instant Signal" (0 Right Bars) option and a bullish/bearish candle Color Filter. (Color Filter is Formation only)
-
Smart Breakout Memory: An intelligent internal memory system programmed to ignore duplicate entries if the market repeatedly chops around the same broken fractal line.
-
Advanced Trade Management: Systematically manages unrealized profits using a mathematical Risk/Reward (R-Multiple) Step Trailing Stop algorithm.
-
Daily Forced Close: An optional mechanism that attempts to automatically close all active trades at a specific server hour to avoid overnight swaps or weekend gaps.
LEGAL WARNING AND DISCLAIMER:
This software is provided 'as is' and 'as available' without any warranty of any kind. The developer does not guarantee that the EA is entirely error-free, bug-free, or will flawlessly execute every intended function under all terminal or server conditions.
- Max Valid Signal Duration (Sec): If a valid setup occurs on a new candle, the EA has this many seconds to execute the trade. If server lag or high spread delays the execution beyond this limit (e.g., 20 seconds), the signal is cancelled to prevent late entries.
- Blacklist Max Retry Limit: The permanent hard-stop safety feature. If the EA attempts to modify a trailing stop or force-close an order and the broker rejects it this many times in total (e.g., 18 times), the EA permanently blacklists that specific ticket number and will never attempt to touch it again.
- CRITICAL WARNING: Do not set this too low (e.g., 1 or 2). If you set it to 1, a single temporary network glitch while moving the Trailing Stop or executing the Daily Forced Close will cause the EA to permanently blacklist the trade, meaning your trailing stop will freeze forever and your trade won't close at the scheduled time! Recommended: 15-20.
- Server Request Cooldown (Sec): The Baseline Delay (Step 1). This acts as your primary defense mechanism against server spam. It is the standard wait time targeted to pass between any modifications made to the same order. For example, if the Trailing Stop moves your SL, the bot is programmed to wait for this amount of time (e.g., 5 seconds) before sending a new modification request for that specific order. This setting is designed to minimize the risk of spamming the broker on every single price tick.
- Note: The EA intelligently tracks modification and closure cooldowns separately. This is designed to help prevent a recent trailing stop adjustment from blocking an urgent daily forced close command.
- Blacklist Error Threshold: The Escalation/Trigger Stage (Step 2). It works directly in connection with the "Cooldown" and "Block Duration". If the bot sends a request (aiming to comply with the 5-second cooldown rule above) but the broker rejects it consecutively (e.g., 3 times in a row), the EA assumes that the server is struggling, lagging, or actively rejecting the action. It then prepares to put that specific order into a much longer "sleep" mode.
- Blacklist Block Duration (Sec): The Penalty Box (Step 3). Linked directly to the "Error Threshold" above. Even if your normal wait time is only 5 seconds, once the bot hits those 3 consecutive errors, this setting overrides the normal cooldown and aims to force the bot into a "sleep mode" for a much longer period (e.g., 30 seconds). Its purpose is to help temporarily stop interacting with that order, giving the broker's server enough time to recover from whatever is causing the errors.
- Example of how they work together: The bot tries to move the Trailing Stop and fails. It waits 5 seconds (Cooldown/Step 1). It tries again and fails again. It waits for another 5 seconds. It tries a 3rd time and fails. The bot has reached the Error Threshold (3)! Now, instead of waiting 5 seconds, it is programmed to wait for 30 seconds (Block Duration/Step 3) before making a 4th attempt.
- Min Duration Between Requests (Ms): Global delay. The overall speed limit for the EA across all orders (1000 Ms = 1 Second). It helps to reduce the risk of the EA sending more requests per second than the broker allows (which could potentially be perceived as an HFT violation).
- Note: This global delay is designed to apply to every type of server interaction (opening, modifying, or closing a trade). After any action, the EA attempts to pause (sleep) for this specified duration before initiating a new request.
- Min Cooldown Between Ticks (Ms): By skipping extremely fast, insignificant micro-fluctuations in price, this setting aims to reduce the CPU load on your computer or VPS.
- Magic Number: The unique identification number that allows the EA to recognize its own trades. If you are using another EA on the same account, the numbers must be different.
- Custom Comment: The custom text/label attached to every order opened by the EA.
- CRITICAL MEMORY NOTICE (Terminal Restarts & EA Reloads): Please be aware that the EA's internal "Blacklist" and "Cooldown" tracking systems are stored in the terminal's active memory (RAM). If you remove the EA from the chart and re-attach it, change the chart's timeframe, or if the MetaTrader 5 terminal is closed, crashes, or restarts (e.g., a VPS reboot), these safety memories will be completely reset. Upon restarting, the EA will treat all previously blacklisted or cooling-down orders as entirely new.
SYSTEM ENTRY LOGIC & FRACTAL SETTINGS
This Expert Advisor utilizes Price Action (Fractals) as the primary entry trigger, while moving averages (EMAs) strictly dictate the allowable trend direction. The EA operates in one of two distinct entry modes:
Entry Strategy (MODE 1: ENTRY_FORMATION): The EA enters the market the exact moment a new structural Fractal is confirmed and fully formed (after the defined Right Bars close), provided the EMAs are aligned.
-
Buy Signal: A Support (Bottom) Fractal is confirmed + EMAs indicate an Uptrend.
-
Sell Signal: A Resistance (Top) Fractal is confirmed + EMAs indicate a Downtrend.
Entry Strategy (MODE 2: ENTRY_BREAKOUT): Instead of entering when a fractal forms, the EA treats the most recent fractals as strict Support and Resistance levels. It waits for the market to aggressively break through these lines.
-
Buy Signal: The EA identifies the most recent Resistance (Top) Fractal peak. If a newly completed candle aggressively breaks and closes above this resistance level + EMAs indicate an Uptrend, a Buy trade is triggered.
-
Sell Signal: The EA identifies the most recent Support (Bottom) Fractal valley. If a newly completed candle aggressively breaks and closes below this support level + EMAs indicate a Downtrend, a Sell trade is triggered.
- Smart Breakout Memory: The EA features a built-in level-memory system. Once a specific fractal level is broken and a trade is triggered, the algorithm registers that exact price level. If the market pulls back and repeatedly breaks that identical line again, the bot is programmed to ignore these subsequent crosses to prevent duplicate or spam entries. Instead, the system requires a completely new fractal structure to form and break before considering the next trade.
-
Fractal Left / Right Confirmation Bars: Defines the structural strictness and shape of your fractals for BOTH entry modes. (e.g., Left=2, Right=2 means a peak is only valid if 2 candles to the left and 2 candles to the right are lower).
-
In Breakout Mode: These numbers define how strong/wide the Support and Resistance anchor levels must be before the EA accepts them as valid breakout zones.
-
In Formation Mode: The 'Right Bars' act as your entry confirmation delay. If set to 2, the bot waits 2 full candles after the structural peak/valley to confirm the reversal before entering.
-
Instant Signal Feature: You can set the Right Confirmation Bars to 0. This removes the confirmation wait time, allowing the bot to aggressively and instantly trigger a signal the exact moment the Left Bars condition is met!
-
- Use Color Filter (For Formation Only): An advanced price-action momentum filter. If True, a Buy (Support) Formation is ONLY valid if the "Right Confirmation Bars" close as bullish (green) candles. A Sell (Resistance) Formation is ONLY valid if the right bars close as bearish (red) candles. This intelligently helps filter out weak structural pivots that lack real momentum. (Note: This filter does not apply if Right Bars are set to 0, or if using Breakout Mode).
- Stop Loss Mode: Choose the mathematical logic for your SL:
- SL_FRACTAL: Places SL based on previous structural swing highs/lows.
- SL_FIXED_POINTS: Uses an exact point distance from your entry.
- SL_ATR: Calculates dynamic SL based on live market volatility.
- Min SL Distance (Points): The minimum Stop Loss distance allowed (10 Points = 1 Pip). If the Fractal or ATR mode calculates an SL that is dangerously tight (inside the spread), the EA expands it to this exact value to help protect you from instant spread stop-outs.
- Fractal Left/Right Bars: (Only for Fractal SL). Defines how many candles to the left and right must be lower/higher to validate a swing peak or valley.
- ATR Timeframe / Multiplier / Period: Configures the dynamic ATR SL calculation. (e.g., ATR value × 1.5 Multiplier).
- Use Stop Area Filter: A technical safety mechanism. Checks the final calculated SL distance before placing the trade.
- Min / Max Stop Limit Points: Works together with the Area Filter. If the calculated SL is smaller than your Min limit, or larger than your Max limit (meaning the market is too chaotic), the EA flags it as an invalid setup and will NOT trade.
- Use Min SL On Area Fail: Linked to the Min/Max Limits above. If the rule above fails (e.g., SL is out of your allowed range), setting this to True overrides the cancellation. Instead of skipping the trade, it forces the EA to open the trade using your Min SL Distance value.
ECONOMIC CALENDAR NEWS FILTER (Auto-Detection)
This advanced module is designed to help protect your account from extreme volatility and slippage spikes caused by major macroeconomic releases.
-
Enable News Filter: Once activated, the EA intelligently scans the built-in MT5 Economic Calendar. It supports 8 Major Currencies (USD, EUR, GBP, JPY, CHF, CAD, AUD, NZD). The EA will automatically block new entries if your active chart contains at least one of these supported currencies (e.g., if attached to EURGBP, it monitors both; if attached to EURTRY, it monitors EUR news only).
-
Always Block USD News: A crucial safety mechanism. High-impact USD news (like NFP or FOMC) often creates massive volatility across the entire forex market, not just USD pairs. If enabled, the EA will pause trading during major USD events, even if you are trading a cross-pair like EURJPY or AUDCAD.
-
Mins Before / After News: Defines your strict "No-Trade Window." The EA is programmed to stop looking for new entries this many minutes before the event and aims to wait this many minutes after the release before resuming normal operations.
-
Min News Importance: Allows you to filter out market noise and focus strictly on high-tier data (e.g., choosing to block only "High / 3-Star" events).
- CRITICAL NEWS DISCLAIMER: This filter is specifically designed to block new entry signals only; it does not force-close your active open positions. Time calculations operate strictly on Broker Server Time (Market Watch), not your local computer clock. Furthermore, the EA relies entirely on the built-in economic calendar data feed provided directly by the MetaTrader 5 platform. The developer has no control over this feed and completely disclaims any liability for financial losses, prop-firm violations, or slipped trades resulting from platform synchronization failures, missing data, or delayed event times.
- This system does NOT trail by standard points. It mathematically trails based on Risk/Reward (R) multiples. (1.0R = Your initial Stop Loss point risk).
- Enable Step Trailing: Turns the system on or off.
- 1. Activation Level (RR): The floating profit milestone required to wake up the trailing engine (e.g., 1.0 means trailing starts when profit equals your initial SL risk).
- 2. Initial Lock Point (RR): Where to move the SL upon the first activation.
- 3. Step Frequency (RR): How much further the profit must travel to trigger the next SL movement.
- 4. SL Shift Amount (RR): How far to move the Stop Loss at every step.
- Example of how they work together: If Activation is 1.0, Lock Point is 0.0, Frequency is 1.0, and Shift is 0.5. When price hits 1.0R profit, SL moves to Breakeven (0.0). Then, when price hits 2.0R, SL moves to +0.5R. When price hits 3.0R, SL moves to +1.0R, systematically adjusting the Stop Loss to help protect unrealized profits.
- Risk/Reward Ratio (For TP): The EA calculates your exact Stop Loss distance and multiplies it by this value to place your Take Profit. (e.g., A ratio of 3.0 means if your SL is 20 pips, your TP will be exactly 60 pips).
- Risk Percentage (%): Calculates the exact lot size dynamically based on your account balance and Stop Loss distance. If the SL is hit, the EA aims to limit your loss to approximately this percentage (excluding market slippage or gaps).
- Allow Min Lot: If the mathematically calculated lot size is smaller than the broker's minimum (e.g., <0.01), setting this to True forces a 0.01 lot entry. Setting it to False cancels the trade safely.
- Custom Max Lot: A hard ceiling limit. If the risk calculation outputs 20 lots but you set this to 5.0, the EA will forcefully reduce the entry to exactly 5 lots.
- Max Spread (Points): If the live broker spread exceeds this limit at the exact moment of execution, the trade is cancelled. (e.g., 300 points = 30 pips).
- Manual Commission (One Way): Enter your broker's one-way commission per 1 Lot (e.g., 3.0 for $3). The EA mathematically includes this cost directly into the Stop Loss risk calculation, aiming to keep your true loss as close as mathematically possible to your Risk Percentage, even after commission deductions!
- Max Daily Trades: A daily hard limit on how many trades the EA can open. If set to 1, the bot will only take the first valid setup of the day and then stop looking for new trades until the next day (0 = Unlimited).
- Allow Hedging: If False, the EA strictly blocks opposing signals (e.g., it will ignore a new Buy signal if a Sell trade is currently active).
- Maximum Open Positions: A hard limit on concurrent open trades. Once reached, new signals are ignored.
EMA SETTINGS (Trend Alignment & Filters)
The EA uses up to 3 EMAs (Fast, Slow, EMA3) and the current Price to establish the strict trend direction. You can enable or disable the Slow EMA and EMA3 independently. The algorithm only evaluates the indicators that you have activated.
-
Include Price in EMA Alignment: Determines whether the completed candle's Close price must mathematically reside on the correct side of the Fast EMA.
-
Alignment Conditions for a BUY (Long) Trade: (For Sell trades, the exact opposite mathematical relation applies)
- All EMAs ON + Include Price (True): Price > Fast EMA > Slow EMA > EMA3
- Slow EMA OFF + EMA3 ON + Include Price (True): Price > Fast EMA > EMA3 (Slow EMA is ignored)
- Only Fast EMA ON + Include Price (True): Price > Fast EMA (2nd and 3rd EMAs are ignored)
- All EMAs ON + Include Price (False): Fast EMA > Slow EMA > EMA3
- PURE FRACTAL MODE (Trend Filter Disabled): If you disable the Slow EMA, the 3rd EMA, AND exclude the Price (False), the EA effectively bypasses the EMA trend filter entirely. In this specific state, the algorithm transforms into a "Pure Fractal Trader", meaning it will take BOTH Buy and Sell fractal signals purely based on price action, regardless of the overall moving average trend.
- Fast / Slow / EMA3 (Period & Offset): Defines your moving average periods. The 'Offset' function allows you to push the EMA line forward or backward in time.
- Enable MACD Filter: When set to True, the MACD acts as an additional layer of confirmation. The EA will NOT enter a trade based on Fractal logic unless the MACD is also mathematically aligned in the correct direction.
- For Buys: MACD Main > MACD Signal line.
- For Sells: MACD Main < MACD Signal line.
- MACD Fast / Slow / Signal: Standard configuration settings for the indicator.
- Use ATR Filter (Min/Max Levels): If the market is too dead (below Min ATR) or violently chaotic (above Max ATR), the EA will ignore the signal.
- CRITICAL WARNING FOR SYMBOLS: ATR values differ radically across symbols. EURUSD ATR might be 0.00150, while XAUUSD (Gold) might be 3.5. Always measure your specific chart's live ATR before setting these bounds!
- Dual ADX System (MTF): Allows you to check trend strength on two different timeframes simultaneously.
- Min / Max ADX Level: ADX measures trend strength (usually 0 to 100). If the momentum is too weak (below Min, e.g., < 22) or dangerously overextended (above Max, e.g., > 60), the EA cancels the entry.
- Use Day Filter: If False, the EA trades every day the market is open.
- Trade Monday to Sunday: Individual toggles for each day of the week. Allows you to block trading on specific days (like Sundays for crypto or Fridays to avoid weekend gaps).
- Enable Time Window Logic: If enabled, the EA will only look for trade setups within a specific time range.
- Window Start / End (Hour & Minute): Defines the exact broker server time range (e.g., Start 01:30 - End 23:50). The EA will only accept entry signals that occur within this specific timeframe. If a signal forms outside this window, it is ignored.
- Enable Forced Time Close: Attempts to automatically close all active trades at the exact specified time below. Highly recommended for avoiding overnight swap fees or weekend gaps.
- CRITICAL WARNING FOR SERVER TIME: This function uses BROKER SERVER TIME, not your local computer time! Ensure you calculate your desired closing time based on your broker's "Market Watch" clock.
- Apply ONLY on Fridays: If True, trades can be held overnight during the week but are forced to close on Friday evenings before the market closes.
- Close Hour (0-23) & Minute (0-59): The exact server hour and minute to execute the forced close.
- Show Indicators: Draws the active EMA lines and indicator sub-windows (MACD, ADX, ATR) onto your chart for visual confirmation and backtesting.
- Enable Debug Logs: An advanced diagnostic tool. Prints human-readable explanations in the MT5 'Experts' tab. If a trade is skipped, the log tells you exactly why (e.g., "CANCELLED: Spread is too high", "MACD not aligned", or "ATR is out of bounds").
