Hello all, just playing around with an AI coding agent to generate MetaTrader4 Expert Advisor. I use multiple AI coding agents with the exact AI prompt (copy-paste).
Please study the following prompt if you want to make your own EA's. Not sure if this will work for another trading platform, I only use MetaTrader4.
#####
Discussion
We can't stop spammers from every Forex Factory thread, but let's try to limit our discussion to these three major issues:
- general: which AI agent generates easy-to-use EA (including file / folder structure, documentation etc.)
- trader perspective: which AI agent gives you the biggest profit (back test, demo or real account)
- programmer perspective: which AI agent produces the best code snippet for future expansion / development
#####
Note: I am not affiliated with any AI coding agent, both free and paid please do your own research on which coding agent will work best for you.
#####
AI prompt:
Please study the following prompt if you want to make your own EA's. Not sure if this will work for another trading platform, I only use MetaTrader4.
#####
Discussion
We can't stop spammers from every Forex Factory thread, but let's try to limit our discussion to these three major issues:
- general: which AI agent generates easy-to-use EA (including file / folder structure, documentation etc.)
- trader perspective: which AI agent gives you the biggest profit (back test, demo or real account)
- programmer perspective: which AI agent produces the best code snippet for future expansion / development
#####
Note: I am not affiliated with any AI coding agent, both free and paid please do your own research on which coding agent will work best for you.
#####
AI prompt:
Inserted Code
# AI Prompt: Generate a Professional MetaTrader 4 Expert Advisor (MQL4) --- # Role Act as a senior quantitative trader, MetaTrader 4 (MQL4) expert, Renko trading specialist, and software architect. Develop a production-quality MT4 Expert Advisor implementing a **Renko Margin Pyramiding Strategy** with professional risk management, modular architecture, optimized execution, and detailed documentation. The EA must be written using modern MQL4 best practices, highly configurable, efficient, and suitable for both backtesting and live trading. --- # Project Goal Create a fully automated or semi-automated Renko pyramiding EA that continuously builds positions during strong trends while using the account's available margin as the primary scaling mechanism. Unlike traditional EAs that limit exposure using fixed lot sizes and stop losses, this strategy intentionally uses margin utilization as the scaling model. Each group of trades is treated as one independent **Trading Session (Basket)**. --- # Strategy Overview The EA should: - Trade only on Renko charts. - Detect market trend. - Open the initial trade automatically or manually. - Add new positions whenever another Renko brick confirms the trend. - Continue scaling until: -- Basket Take Profit reached -- Trend reversal detected -- Margin Level falls below the configured threshold -- Margin stop-out occurs (acceptable risk) --- # Core Strategy ## 1. Trend Detection Allow multiple selectable filters. Examples: **EMA Filter** 50 EMA Buy only above EMA Sell only below EMA **Dual EMA** 20 EMA + 50 EMA **SuperTrend** Optional **ATR Filter** Minimum volatility requirement **ADX Filter** Trade only if ADX > threshold. **Multi-Timeframe Confirmation** Example: Renko direction + M15 EMA + H1 EMA ## 2. Entry Logic Buy Conditions: - Trend = Bullish - New bullish Renko brick closes - Margin Level > configured threshold - Spread acceptable - Trading session active Open one Buy. Sell Opposite logic. ## 3. Pyramiding Logic Every new Renko brick in the trend: Open another position. Example Brick 1 Buy Brick 2 Buy Brick 3 Buy Brick 4 Buy ... Unlimited additions until exit conditions. --- # Basket Management Treat every trading sequence as ONE basket. Each basket contains: - Basket ID - Direction - Start time - Average entry - Total lots - Floating P/L - Used margin - Margin Level - Number of trades - Highest floating profit - Maximum drawdown Every order must carry: - Magic Number - Basket ID - Order Comment Example: RENKO_BUY_BASKET_004 --- # Trading Session Rules Configurable: Maximum baskets/day Example: 10 Each basket starts when: First position opens. Basket ends when: - TP reached - Trend reversal - Manual close - Margin stop-out --- # Margin-Based Scaling This is the EA's unique feature. Instead of lot progression based on martingale: Scaling depends on available margin. Example: If Margin Level > 500% Open trade. If Margin Level > 300% Open trade. If Margin Level > 200% Open trade. If Margin Level > 120% Continue opening. Below threshold No new entries. User parameter: Minimum Margin Level Default: 120% --- # Lot Size Models Provide selectable methods. ## Fixed 0.01 ## Fixed Risk Balance % ## Equity % ## Margin % ## Dynamic Lot based on free margin. ## ATR Position Size Volatility adjusted. --- # Optional Lot Progression Selectable. Constant Linear Geometric Multiplier Fibonacci Custom Array Default: Constant lots. --- # Exit Logic Selectable. ## Basket Take Profit Currency Example USD 20 ## Basket TP % Example 5% ## Opposite Renko Signal ## EMA Cross ## ATR Trailing Exit ## Moving Average Exit ## Time Exit ## Maximum Drawdown Exit ## Emergency Equity Stop Example 20% --- # Scale-Out Logic Support partial profit taking. Example At 25% target Close 20% At 50% Close another 30% At 75% Close another 30% Final target Close remaining. Alternative: Close oldest positions first. Or newest first. Or highest profit first. --- # Semi-Automatic Mode ## Mode 1 Fully Automatic EA opens everything. ## Mode 2 Semi Auto User opens first trade. EA detects it. Creates basket. Handles: - Scaling - Exit - Dashboard Automatically. --- # Dashboard Professional on-chart dashboard. Display: ## Account - Balance - Equity - Floating P/L - Margin Used - Free Margin - Margin Level ## Current Basket - Basket ID - Direction - Trades - Lots - Average Entry - Floating Profit - Profit Target - Drawdown - Used Margin ## Market - Trend - EMA - ATR - ADX - Spread - Brick Size ## Statistics - Today's baskets - Winning baskets - Losing baskets - Profit today - Win rate - Largest basket - Largest DD - Profit factor - Average trades/basket --- # Notifications Support: - Popup - Sound - Push Notification - Email - Telegram API (optional) Notify: - Basket opened - New pyramid position - Basket TP - Margin warning - Margin below threshold - Trend reversal - Emergency exit --- # Inputs General Magic Number Enable Buy Enable Sell Auto Trading Semi Auto Max baskets/day Max spread Trading hours Renko Brick size ATR brick option EMA EMA period EMA type EMA timeframe ATR ATR period ATR multiplier ADX Period Minimum ADX Risk Initial lot Risk % Margin trigger % Emergency equity stop % Basket TP Basket SL Maximum DD Pyramiding Maximum trades Unlimited mode Minimum bricks between entries Lot progression Scale-out settings Dashboard Enable Font size Theme Notifications Enable alerts Push Email Telegram --- # Optimization Parameters Optimize: - Brick Size - EMA - ATR - ADX - Margin Trigger - Basket TP - Risk % - Lot Size - Trading Hours - Spread Filter --- # Performance Requirements - Efficient code - No duplicated logic - Modular functions - Low CPU usage - Minimal memory allocation - Robust error handling - Automatic retry for failed orders - Full logging - Compatible with MT4 Strategy Tester - Multi-symbol support - Multi-basket support - Broker with 4- and 5-digit pricing - ECN/STP compatible - FIFO compatibility option --- # Recommended Starting Presets ## Conservative - Brick Size: 1520 pips (or ATR ื 1.5) - Trend Filter: 50 EMA + ADX > 25 - Margin Trigger: >300% - Lot Size: 0.01 fixed - Max Basket TP: 35% of account - Scale-Out: 25% / 50% / 75% profit milestones ## Balanced - Brick Size: 1015 pips (or ATR ื 1.2) - Trend Filter: 50 EMA - Margin Trigger: >200% - Lot Size: 0.010.02 - Basket TP: 58% - Partial profit enabled ## Aggressive - Brick Size: 510 pips (or ATR ื 0.8) - Trend Filter: Fast EMA + Slow EMA - Margin Trigger: >120% - Dynamic lot sizing - Unlimited pyramiding - Basket TP: 815% --- # Brick Size Recommendations Instead of fixed values, support **ATR-based adaptive Renko**: - Low volatility: ATR ื 0.8 - Medium volatility: ATR ื 1.0 - High volatility: ATR ื 1.21.5 This allows the EA to adapt automatically to changing market conditions. --- # Suitable Markets Prioritize instruments with a high **volatility-to-cost ratio**, calculated as: **Index = Average Daily Range ๗ (Spread + Commission in points)** Higher values indicate more efficient markets for this strategy. Typical candidates include major stock indices, gold (when trading costs are competitive), liquid forex pairs (such as EUR/USD and GBP/USD), and highly liquid futures/CFD instruments. --- # Deliverables Generate: - Fully documented MQL4 source code (.mq4) - Modular helper libraries (.mqh) - Input parameter documentation - Installation guide - User manual - Strategy Tester optimization guide - Flowcharts for trade management and basket lifecycle - Inline code comments explaining all major functions and algorithms **Important**: The EA should emphasize robust basket management, adaptive Renko filtering, efficient margin-aware scaling, and configurable exit logic while avoiding overfitting to a single market or broker.
Attached File(s)