How ersingencturk/freeexpertadvisor works
Project type and purpose
• This is an open-source Forex Expert Advisor (EA) script written in MQL4 for the MetaTrader 4 platform.
• Its purpose is to run on live or back-testing charts, apply three overbought/oversold strategies, and automatically open and close scalping trades on the 5-minute timeframe with built-in risk management.
File structure
• Top-level:
– FreeExpertAdvisor.mq4 – the entire EA code (no separate frontend/backend, all logic lives here)
– README.md – project overview, settings, strategy descriptions
– LICENSE
• No subdirectories: implies a single-component codebase that plugs into the MT4 terminal.
README for additional insights
• Core features: three strategies, true stop-loss plus virtual stop-loss/take-profit via ATR multiplier, FIFO compliance, one trade at a time, dynamic lot sizing.
• Supported symbols and broker requirements.
• Configurable parameters: fixed lots, dynamic lot % risk, hard stop-loss, GMT offset, chart symbol.
• Backtesting results shown via screenshots.
a. MetaTrader 4 Terminal – host application that loads the EA and provides market data & order API.
b. Market Data Feed – real-time tick data (or historical data in the back-tester).
c. FreeExpertAdvisor EA – subdivide into internal modules:
• Initialization & Parameter Loader
• Strategy Engine – implements three overbought/oversold algorithms
• ATR Module – computes current ATR and virtual stop-loss/take-profit levels
• Risk Management Module – dynamic lot calculation or fixed lot, single-order enforcement
• Order Execution Module – MT4 order/send API calls, real SL vs virtual SL/TP handling
• Logging/Monitoring (optional)
d. Broker Server – receives orders from MT4, returns fills & trade status.
e. Backtest Engine (MT4) – alternative path where historical data flows into the EA.
Relationships and interactions
• From Strategy/Risk Management → Order Execution → Broker Server, then back to EA for confirmations.
• Parameter Loader feeds the Strategy and Risk Management modules at startup.
• Two modes: Live trading (real ticks) vs Backtesting (historical data). Show these as parallel paths.
Architectural patterns & design principles
• Modular design within a single script: separate concerns (init, strategies, risk, execution).
• Event-driven: OnTick callback drives execution loop.
• Single instance enforcement & FIFO compliance ensure orderly trade flow.
• Configuration via input parameters for flexibility and reuse.
Technologies, frameworks, and libraries
• MQL4 language (MetaQuotes proprietary), MT4 platform APIs (OnInit, OnTick, OrderSend, etc.).
• No external libraries; all code is self-contained.
Detail level
• Essential MT4 interactions (OnInit, OnTick, OnDeinit, OrderSend, OrderModify, etc.).