Overview of the EA's Functionality
This Expert Advisor (EA) is designed for automated trading on MetaTrader 5, primarily for forex pairs like EURUSD (with options to restrict to specific symbols). It operates as a grid-like pending order system focused on reversal entries, using a Simple Moving Average (SMA) and candle analysis to place buy limit and sell limit orders. The EA emphasizes controlled entry conditions, visual aids on the chart (e.g., buttons, lines, labels, rectangles, and arrows), and customizable parameters for risk and profit management. It does not use stop-losses by default but relies on profit targets, drawdown limits, and manual interventions.
The EA runs on every tick but primarily acts on new bar formations (e.g., when a new candle closes). It checks trading permissions (e.g., hours, symbols, external conditions like AUDCHF/CADCHF buys) before placing orders. It also enforces strict trading rules, such as closing unauthorized trades on non-allowed symbols.
Key Components and Workflow
- Initialization and Setup:
- Validates inputs (e.g., trading hours, lot increments, expiration date).
- Creates chart objects: Buttons for manual control (e.g., "Close All Trades", "Allow Buy"), labels for status (e.g., drawdown, time, largest candle), and visual indicators (e.g., SMA as trend lines, rectangles around recent bars, arrows on largest/smallest candles).
- Calculates SMA handle for entry conditions.
- Parses allowed symbols and trading hours (configurable per day as comma-separated lists, e.g., "0,1,2" for hours 0-2).
- Entry Logic (Triggered on New Bar Close):
- Conditions for Placement:
- Trading must be enabled (not disabled by profit targets or buttons).
- Current hour must be in allowed trading hours (unless ignored via button).
- No active AUDCHF buy (if CloseAllOnAUDCHFBuy is true, it closes everything).
- No active CADCHF buy (if DisablePendingOnCADCHFBuy is true, it skips pendings).
- Symbol must be allowed (if EnableStrictPairs is true).
- Last closed candle's body must be at least 1/5th the size of the largest body in the last InpPeriod (default 21) bars (dynamic threshold to filter small candles).
- Buy Limit Orders (if "Allow Buy" enabled):
- Optional: Last candle must be bearish and close below SMA (if CheckBearishCandle true).
- Places two buy limits below the last candle's low:
- First: Offset by the full body size of the largest recent candle, lot size = LotSize (adjusted).
- Second: Offset by double that size, lot size = LotSizeSecond (adjusted), optional TP at entry + half largest body (if SetTPOnSecondPending true).
- Orders have custom comments (e.g., "BuyLimit1_M15") and no SL/TP unless specified for second.
- Respects min separation (based on smallest recent candle body) to avoid clustering.
- Optional cutoff line (draggable blue horizontal line) to prevent orders below a price.
- Sell Limit Orders (if "Allow Sell" enabled):
- Similar to buys but for bullish candles above SMA (if CheckBullishCandle true).
- Places above the high, with offsets upward.
- Optional cutoff line (draggable red horizontal line) to prevent orders above a price.
- Visual Feedback: Draws a rectangle around the last InpPeriod bars, yellow arrow on largest candle, blue dot on smallest, yellow dots on qualifying candles. SMA drawn as white trend line segments.
- Cleanup: If DeletePendingOnSMACross true, cancels sell limits if price closes below SMA or buy limits if above.
- Daily Close: At specified EST time (default 22:30), removes all pendings and disables buy/sell (if enabled).
- Conditions for Placement:
- Ongoing Monitoring (Every Tick):
- Updates visuals (e.g., largest candle label, day/time, trading status).
- Applies TP to manual pending orders (non-EA placed) if no TP set (uses ManualTradeTP pips).
- Checks for AUDCHF/CADCHF buys and reacts (close all or disable pendings).
- Enforces symbol restrictions by closing/deleting unauthorized trades/orders.
How It Takes Profit
The EA focuses on collective profit closure rather than per-trade TPs (except optional on second pendings). It does not use trailing stops or breakeven.
- Automated Profit Closure:
- Percentage-Based Targets:
- Closes trades when profit hits CloseProfitPercent (default 0.5%) of account balance.
- Mode: Separate (buy/sell profits checked independently) or Combined (total profit).
- Also cancels all pendings when triggered.
- Overall profit target (ProfitTargetPercent, default 99.9%): Closes everything and disables trading permanently.
- Closes trades when profit hits CloseProfitPercent (default 0.5%) of account balance.
- Manual Closure:
- Buttons: "Close All Trades" (closes positions and cancels pendings, excluding AUDCHF first if needed), "Close Profitable Trades" (only positive-profit positions).
- Per-Order TP:
- Optional on second pending orders only (SetTPOnSecondPending): Set to entry ± half the largest recent candle body (buy: +half, sell: -half).
- For manual pendings: Auto-adds ManualTradeTP pips if missing.
- Percentage-Based Targets:
- Other Triggers:
- Closes at daily EST time (pendings only).
- Closes on AUDCHF buy detection (if enabled).
- If profit target reached during monitoring, it logs the reason and updates a label.
Profit is calculated including swaps, and closures use retries (up to 3) for reliability.
How It Manages Risk
Risk management is multi-layered, focusing on lot sizing, exposure limits, and protective closures. No hard SLs, but drawdown-based stops and filters prevent over-trading.
- Lot Sizing:
- Base lots (LotSize for first, LotSizeSecond for second, defaults 0.01/0.02).
- Scaled by balance: Multiplier = floor(balance /Â LotSizeIncrement, default 10000) + 1.
- Risk tolerance multiplier: PropFirm (1x), Conservative (2x), Moderate (4x), Aggressive (8x).
- Clamped to symbol min/max lot sizes.
- Example: For $20,000 balance and increment 10,000, multiplier=3; Moderate risk makes first lot = 0.01 * 3 * 4 = 0.12.
- Exposure Controls:
- Min order separation: Based on smallest recent candle body to avoid tight grids.
- Cutoff lines: Manually set/dragged to block pendings beyond a price (e.g., no buys below a support).
- Symbol restrictions: Closes/deletes trades on non-allowed pairs (e.g., only EURUSD).
- No orders if candle body too small (filters noise).
- Trading hours: Restricts to specific hours per day to avoid low-liquidity periods.
- External pair checks: Pauses on CADCHF buy; closes on AUDCHF buy.
- Protective Closures:
- Drawdown Limit: Closes all trades/pendings if equity drop >= DrawdownClosePercent (default 99.9%) of balance.
- SMA Cross Cleanup: Cancels opposites if price crosses SMA (if enabled).
- Retries on closures (up to 3 with 1s sleep) to handle errors.
- Manual buttons for emergency close/disable.
- Other Safeguards:
- Slippage tolerance (default 30 points).
- No internet/package installs; runs in isolated REPL.
- License expiration check (hard-coded to 2025-12-31).
- Logs errors, alerts, and reasons for actions (e.g., "Drawdown reached 99.9%").
Overall, the EA is conservative in entries (SMA/candle filters) but aggressive in scaling (grid-like pendings, risk multipliers). It's suited for prop firm challenges or managed accounts, with heavy emphasis on user intervention via buttons. Potential risks include unlimited drawdown without SLs and grid accumulation in ranging markets.
How do I get a copy of this Expert Advisor for free?
All of our Expert Advisors on our website are 100% free to download and use as long as they are used with our preferred broker which is OxSecurities. Here's the process to receive access to all of our Expert Advisors 100% for free.
Step 1. Open a live account with OxSecurities and deposit a minimum of $200
Step 2. Open MT5 Account
Step 3. Complete our form using the same name and email address you registered with OxSecurities, and include your OxSecurities MT5 account number. The EA will only function with the provided account number and OxSecurities. If used with a different account, the EA will detect it and become disabled.


