EA Gold Stuff — Detailed Functional Description The EA is a multi-directional, indicator-based trading system designed primarily around an initial signal entry followed by controlled martingale/grid management. It can manage BUY and SELL baskets independently and includes indicator filtering, volatility protection, basket-level profit management, drawdown controls, hedge protection, dynamic loss-reduction closing, manual-trade integration, and an on-chart management panel. 1. Trading Direction The EA has a direction input with three operating modes: BUY ONLY — only BUY initial trades and their associated BUY martingale sequence are allowed. SELL ONLY — only SELL initial trades and their associated SELL martingale sequence are allowed. BUY + SELL — both directions can operate independently when their respective entry conditions are satisfied. A BUY basket and SELL basket can therefore exist simultaneously when both-direction trading is enabled. 2. Initial Trade Entry The first position of a new sequence is the Initial Trade, also considered Trade Number 1 of that sequence. The initial lot size is specified directly in the EA inputs. For example: Initial Lot Size = 0.10 ( editabel) means a newly generated initial BUY or SELL position starts with 0.10 lots. ( its for example) The initial trade is generated from the selected custom signal indicator and its configured timeframe(s). The EA supports multiple initial-entry timeframes. Each timeframe can individually be enabled or disabled. For example: Use Timeframe 1 = true Timeframe 1 = M15 Use Timeframe 2 = true Timeframe 2 = H1 Use Timeframe 3 = false Timeframe 3 = H4 When multiple timeframes are enabled, they must agree with the required initial-entry direction according to the initial signal logic. Current custom initial-entry indicator 3. Initial RSI Lock / Resume This is an additional protection applied only to opening new initial trades. It does not close existing positions and does not directly interfere with existing martingale management. The RSI has configurable: Enable/disable Timeframe RSI period BUY blocking level BUY resume level SELL blocking level SELL resume level BUY behavior If RSI reaches or exceeds the configured BUY block level, new initial BUY entries are locked. Example: BUY Block RSI = 70 BUY Resume RSI = 50 If RSI reaches 70 or higher: Initial BUY = LOCKED It remains locked even if RSI subsequently moves from 70 to 68, 65, 60, etc. Only when RSI falls to 50 or below does: Initial BUY = RESUMED This is therefore a stateful hysteresis filter, rather than a simple instantaneous RSI condition. SELL behavior The opposite logic applies. Example: SELL Block RSI = 30 SELL Resume RSI = 50 If RSI falls to 30 or below: Initial SELL = LOCKED It remains locked until RSI subsequently rises to 50 or higher. Importantly, unlocking an entry direction does not automatically open a trade. It merely permits the normal initial-entry strategy to operate again. 4. Initial Bollinger Band Lock / Resume A second optional initial-entry protection uses: Bollinger Bands Its parameters include: Enable/disable Timeframe Bollinger period Standard deviation Resume price distance This filter also affects initial trades only. Lower Bollinger Band When price reaches/touches the lower Bollinger Band: Initial SELL entries = LOCKED The SELL side remains locked until price has moved upward by the configured price-dollar distance relative to the lower band. Example: BB Resume Distance = $5.00 If the lower band is around: 3300.00 the recovery condition is approximately: 3305.00 subject to the band's movement itself because the Bollinger Band is dynamically recalculated. Upper Bollinger Band When price reaches/touches the upper Bollinger Band: Initial BUY entries = LOCKED BUY remains locked until price falls sufficiently below the upper band according to the configured resume distance. This creates the same lock/resume hysteresis concept as the RSI filter. 5. Trading Days Trading days can be enabled or disabled individually. The inputs cover: Sunday Monday Tuesday Wednesday Thursday Friday Saturday The purpose is to prevent new initial entries outside the permitted trading days. 6. Trading Times The EA supports configurable trading-hour ranges. For example: 4-10,12-15,15-18 This defines multiple permitted entry sessions during the day. Existing positions continue to be managed outside these entry periods. The time restriction is intended to control new strategy entry, not to disable risk management. 7. Martingale System After an initial position enters drawdown, the EA can progressively add positions in the same direction. For example: Trade 1 = Initial BUY Trade 2 = Martingale BUY #1 Trade 3 = Martingale BUY #2 Trade 4 = Martingale BUY #3 ... The martingale engine has three major components: Distance, lot multiplier, and entry filters. 8. Multiple Martingale Distance Sets The EA supports multiple martingale configuration sets. Each set contains three important parameters: Starting Trade/Order Number Starting Distance Distance Multiplier Lot Size Multiplier This allows the grid behavior to change as the basket becomes deeper. For example, an early martingale sequence could use relatively small distances, while later positions use larger distances. This is important because later martingale positions do not have to follow the exact same spacing and lot progression as the early positions. 9. Martingale Distance Current version The version currently being tested uses points for martingale distance. A point is based on the broker's _Point value, so the actual price movement represented by 100 points can vary according to the symbol's number of decimal digits. Agreed next revision We have now agreed that martingale distances will instead be expressed as direct price-dollar distances. For example: Martingale Distance = 5.00 For a BUY opened at: 3350.00 the next adverse threshold would be: 3345.00 For a SELL opened at: 3350.00 the next adverse threshold would be: 3355.00 This makes the configuration much easier to understand for instruments such as XAUUSD. The existing distance multiplier will remain. For example: Base Distance = $5.00 Distance Multiplier = 1.50 produces an effective distance of: $7.50 where that multiplier applies. This dollar-distance conversion is agreed but has not yet been coded into the version currently being tested. 10. Martingale Lot Multiplier Each martingale set has its own lot-size multiplier. The next martingale lot is calculated from the previous relevant strategy trade. Example: Previous Lot = 0.10 Lot Multiplier = 1.50 Next martingale: 0.10 × 1.50 = 0.15 lots Then, if the same multiplier remains active: 0.15 × 1.50 = 0.225 The final lot is normalized according to the broker's permitted volume step. 11. Maximum Martingale Lot Size The EA contains a hard maximum martingale lot restriction. Example: Maximum Lot = 2.00 Even if the multiplier calculation produces: 2.50 3.00 4.00 the EA must not open a martingale position larger than the configured maximum. 12. Maximum Number of Martingale Trades There is also a maximum martingale-trade limit. The initial trade is not counted as a martingale trade. For example: Maximum Martingale Trades = 10 means the sequence can contain: 1 Initial Trade + Maximum 10 Martingale Trades The hedge is also not supposed to count as a martingale trade. 13. Martingale Opening Filters Reaching the required price distance does not necessarily mean a martingale must immediately open. The EA can apply several safety and indicator checks first. Crucially, these systems are individually enabled/disabled using true/false inputs. They are not universally mandatory. The main groups are: ATR Spike Filter Market Safe Filter Indicator Confirmation System 14. ATR Spike Filter Indicator used: Average True Range (ATR) ATR is used as a volatility-protection mechanism. Its parameters include: Enable/disable ATR timeframe ATR period Spike threshold When enabled, if current price movement is considered abnormally large relative to ATR, martingale opening is temporarily blocked. The existing basket remains open and managed normally. This prevents the martingale engine from blindly adding positions during sudden abnormal volatility. 15. Market Safe Filter The Market Safe system is another optional martingale filter. When enabled, it examines multiple aspects of current market behavior. The implementation includes checks based on: Volume Current tick volume is compared against recent average volume. Abnormally high volume can indicate unstable market conditions. ADX Indicator: Average Directional Index (ADX) ADX is used to measure trend strength. Bollinger Band Expansion Indicator: Bollinger Bands Band width is examined to detect rapid volatility expansion. Awesome Oscillator Indicator: Awesome Oscillator (AO) AO behavior is examined as another momentum/market-condition component. OBV Indicator: On-Balance Volume (OBV) The EA examines OBV movement relative to price behavior. Ichimoku Indicator: Ichimoku Kinko Hyo Cloud and Tenkan/Kijun behavior are used as additional market-state information. ATR Expansion Again using: Average True Range Current ATR is compared against historical ATR to detect abnormal volatility expansion. If Market Safe is disabled, these checks do not block martingale entry. 16. Martingale Indicator Confirmation System The martingale engine also has a separate confirmation-voting system. This system can itself be enabled or disabled. Individual indicators inside it can also be independently enabled or disabled. The EA counts successful enabled indicator signals. An input determines how many confirmations are required. For example: Minimum Signals = 3 means at least three enabled indicator conditions must confirm the proposed martingale direction. The indicators currently included are: RSI — Relative Strength Index Used to identify overbought/oversold conditions. For BUY martingale confirmation, RSI can confirm when sufficiently oversold. For SELL martingale confirmation, RSI can confirm when sufficiently overbought. Its timeframe and levels are configurable. MACD — Moving Average Convergence Divergence The EA compares MACD main and signal values. Positive/bullish MACD relationship can confirm BUY. Negative/bearish relationship can confirm SELL. Bollinger Bands For martingale confirmation, Bollinger Bands are separate from the initial-entry Bollinger lock. Price relative to the upper/lower band provides directional confirmation. ADX — Average Directional Index ADX contributes a confirmation when trend strength exceeds the configured threshold. Stochastic Oscillator Stochastic uses configurable: K period D period Slowing Overbought level Oversold level Timeframe Oversold behavior can confirm BUY and overbought behavior can confirm SELL. OBV — On-Balance Volume Changes in OBV provide another directional confirmation. Ichimoku Kinko Hyo Price relative to the Ichimoku cloud provides another trend/directional confirmation. CCI — Commodity Channel Index CCI is another momentum confirmation. Strong positive CCI can contribute to BUY confirmation, while sufficiently negative CCI can contribute to SELL confirmation. 17. Set 1 Hedge System The hedge system specifically protects the situation where the first martingale distance has been reached but the normal first martingale cannot open because its enabled martingale-entry filters reject the entry. Example: Initial BUY = 0.10 Set 1 Martingale should = BUY 0.15 Set 1 distance reached Martingale filter = FAIL Instead of simply doing nothing, the hedge system can open: SELL Hedge = 0.15 Therefore, the hedge uses the same calculated lot size that Martingale Set 1 would have used, including the Set 1 lot multiplier. It does not become Martingale Trade #2. Important hedge issue discovered during testing We have now identified a design problem with the currently tested version. Suppose there is already an independent SELL basket, and a BUY basket generates a SELL hedge. If basket management looks only at position direction, that new SELL hedge can incorrectly become mixed with the existing SELL basket. That can distort: SELL basket profit SELL trailing SELL TP closing decisions Agreed corrected hedge architecture Every hedge will be explicitly linked to the source basket that created it. Therefore: BUY basket → creates SELL hedge means that SELL hedge belongs logically to the originating BUY basket, not to some unrelated existing SELL basket. Similarly: SELL basket → creates BUY hedge means the BUY hedge remains associated with the originating SELL basket. This basket-linked hedge redesign has been agreed but has not yet been coded while you are testing the current version. 18. Manual Trades The EA has: Include Manual Trades = true/false When disabled, manually opened positions are ignored by EA basket management. When enabled, a manual position on the relevant symbol can participate in basket profit management. However, a manual trade must not affect the martingale engine. In particular, it does not affect: martingale numbering active martingale distance set next martingale distance martingale lot multiplier maximum martingale count identification of the previous martingale position Its purpose is purely to allow the trader to manually add a position that can contribute profit toward closing the managed basket sooner. 19. Profit Per Trade Profit management is expressed in account currency (dollars/cents) rather than points or pips. Example: Profit Per Order = $10 Suppose the basket contains: 1 initial trade 4 martingale trades Total: 5 trades The basket TP becomes: 5 × $10 = $50 The different positions can have completely different lot sizes. The EA is interested in their combined monetary result. 20. Commission and Swap Basket profitability is intended to use net profit, including: floating trading profit/loss swap commission/fees This is important because a basket showing $50 gross trading profit may actually produce less than $50 after trading costs. The MQL5 implementation therefore retrieves booked costs from the position/deal history and can estimate the corresponding exit-side commission when required. 21. Virtual Trailing Profit Trailing is also expressed as dollars per participating trade. Example: Trailing Profit Per Order = $5 Profit Per Order = $10 With five participating positions: Trailing activation = 5 × $5 = $25 TP = 5 × $10 = $50 When combined net basket profit reaches $25, the virtual trailing protection becomes active. The EA then attempts to protect that basket-profit level while allowing the basket to continue toward $50. This is a virtual basket trailing mechanism, rather than trying to assign the same physical broker SL to positions having different entry prices and lot sizes. 22. Breakeven Price The EA calculates a monetary-cost-adjusted breakeven price for BUY and SELL baskets. The calculation considers: individual entry prices individual lot sizes swap commission/fees participating basket positions Therefore, it is more meaningful than simply averaging all entry prices. 23. Target Price The panel calculates the approximate market price at which the configured basket monetary target would be reached. For example: 5 positions Profit Per Trade = $10 Basket target = $50 The EA calculates the approximate XAUUSD price required to produce that combined net result. BUY and SELL target prices are calculated separately. 24. Trailing Profit Price The panel also converts the basket's monetary trailing level into an approximate market price. Therefore each side can display something similar to: BUY: BE: 3342.50 Trail: 3347.20 TP: 3351.80 The actual values depend on lots, entries, costs, symbol contract specifications and the configured monetary targets. 25. Daily Profit Target The EA has a configurable daily profit limit. Example: Daily Profit Target = $500 When the calculated daily profit reaches $500, the EA stops opening new trades. Existing positions continue to be managed according to their normal closing/risk logic. Importantly, this is recalculated from the input. If the trader subsequently changes: $500 → $700 and the current daily result is only $550, new trading can resume because the new $700 limit has not yet been reached. 26. Martingale Drawdown Pause This is different from cut loss. Example: Pause Martingale At Drawdown = $1,000 When managed drawdown reaches $1,000: NEW MARTINGALE TRADES = PAUSED Existing positions remain open. The EA continues managing them. 27. Drawdown Recovery Percentage Martingale does not have to resume immediately after drawdown moves just slightly below the pause threshold. A configurable recovery percentage is used. Example: Pause DD = $1,000 Resume Recovery = 50% Martingale resumes when drawdown has recovered by 50%, meaning: $1,000 → $500 For: Recovery = 30% the required improvement is: $1,000 × 30% = $300 so martingale resumes around: $700 drawdown This creates a stateful pause/resume system and avoids repeatedly switching martingale on/off around a single threshold. 28. Cut Loss Cut loss is the hard basket protection. Example: Cut Loss = $2,000 If managed drawdown reaches the configured amount, the EA closes the managed positions rather than merely stopping new martingale trades. Therefore: Drawdown Pause means stop adding martingales, whereas: Cut Loss means close the managed basket/trades. 29. Martingale Closing Strategy This is a separate drawdown-reduction mechanism. It attempts to use profitable newer martingale positions to remove older losing positions. Inputs include: Use Martingale Closing Strategy = true/false Martingale Closing Profit = $2 Closing Rule = 6,1 The positions are dynamically numbered by their current sequence. Example: Trade 1 = Initial Trade 2 = Martingale 1 Trade 3 = Martingale 2 Trade 4 = Martingale 3 Trade 5 = Martingale 4 Trade 6 = Martingale 5 Rule: 6,1 means the newer candidate attempts to close the current Trade #1. Suppose: Trade 1 = -$25 Trade 6 = +$27 Combined: -$25 + $27 = +$2 If: Martingale Closing Profit = $2 the pair qualifies for closing. Both positions are closed. 30. Dynamic Renumbering Trade numbers are not permanently assigned ticket numbers for this strategy. After positions close, the surviving sequence is renumbered. Suppose: 1 2 3 4 5 6 and positions 6 and 1 close. The previous: 2 3 4 5 become: 1 2 3 4 As more martingale trades are subsequently opened, the sequence grows again. This allows the same closing strategy to repeatedly remove older losing exposure. 31. If Trade 6 Cannot Close Trade 1 This was an important part of the agreed strategy. Suppose the rule is: 6,1 but Trade 6 does not generate enough profit to offset Trade 1 plus the required closing profit. Nothing closes. If Trade 7 subsequently opens, Trade 7 becomes the newer candidate attempting to close the current Trade 1. If that fails and Trade 8 opens, Trade 8 attempts it. Therefore, 6,1 effectively means: Once the sequence is sufficiently deep, use the current newest eligible trade to attempt to remove the oldest/current Trade #1 when their combined net P/L reaches the required closing profit. After successful closing, positions are renumbered and the process can repeat. 32. On-Chart Panel The EA contains: Show Panel = true/false The panel provides trading information and manual controls. It has separate BUY and SELL information lines. Each line displays: Number of trades Breakeven price Trailing price Target/TP price Current net basket profit For example: BUY Trades:5 BE:3342.50 Trail:3347.20 TP:3351.80 Net:$18.40 SELL Trades:3 BE:3360.10 Trail:3355.40 TP:3350.80 Net:-$7.20 33. BUY / SELL Pause Buttons The panel contains independent: Pause BUY Pause SELL controls. When BUY is paused, new BUY-side activity is prevented according to the strategy's direction controls while existing positions continue to be managed. The button changes to: Resume BUY Similarly: Pause SELL Resume SELL operate independently. 34. Close BUY / Close SELL Buttons The panel contains: Close BUY Close SELL buttons. They can be used for immediate basket closing. The panel also provides price fields so a close request can be scheduled at a specified market price rather than executed immediately. For example: BUY Close Price = 3355.00 The EA monitors price and closes the applicable BUY basket when the requested level is reached. The same concept applies independently to SELL. 35. Panel Customization Panel appearance is configurable. Inputs include items such as: background color font color button color paused button color active button color font size panel width row height X position Y position This allows the interface to be adapted to different chart layouts and screen resolutions. 36. Diagnostic Logging The EA contains an optional diagnostic mode. When enabled, it can report important internal events such as: Initial BUY locked by RSI Initial SELL resumed by RSI Initial BUY locked by Bollinger ATR spike detected Martingale blocked by indicators Martingale blocked because market is unsafe Set 1 hedge triggered Martingale opened Virtual trailing activated Basket target reached Drawdown pause activated Drawdown recovered Martingale closing pair triggered Cut loss triggered This is especially useful during Strategy Tester testing because we can determine why a trade did or did not open, instead of guessing from the chart. 37. Indicator Summary The complete strategy currently involves the following indicators: RSI — Relative Strength Index — used for the initial BUY/SELL lock/resume system and separately as an optional martingale confirmation. Bollinger Bands — used for the initial BUY/SELL lock/resume system, martingale confirmation, and market-volatility/expansion analysis. ATR — Average True Range — used for martingale spike protection and volatility-expansion analysis. MACD — Moving Average Convergence Divergence — optional martingale directional confirmation. ADX — Average Directional Index — optional martingale confirmation and market-condition analysis. Stochastic Oscillator — optional overbought/oversold martingale confirmation. OBV — On-Balance Volume — optional martingale confirmation and market-condition/divergence analysis. Ichimoku Kinko Hyo — optional martingale confirmation and market-condition analysis. CCI — Commodity Channel Index — optional martingale momentum confirmation. Awesome Oscillator (AO) — used as part of the optional Market Safe analysis. Overall Trading Flow In simplified form, the intended EA operates like this: Initial signal ↓ Trading direction allowed? ↓ Trading day/time allowed? ↓ Initial RSI lock clear? ↓ Initial Bollinger lock clear? ↓ OPEN INITIAL TRADE ↓ Price moves adversely ↓ Required Martingale Set distance reached? ↓ ATR filter (if enabled) Market Safe filter (if enabled) Indicator confirmations (if enabled) ↓ PASS ───────────────→ Open normal martingale │ │ FAIL at Set 1 ↓ Set 1 Hedge enabled? ↓ Open opposite hedge using Set 1 martingale lot ↓ Continue basket management ↓ Profit / virtual trailing / drawdown management ↓ Optional martingale pair-closing strategy ↓ Basket TP / trailing / cut-loss closure