Sp500 Ema Smart Trader
- Experts
- Petar Dimitrov
- Versione: 1.0
- Attivazioni: 5
📌 Product Description
SP500 EMA EA with Smart TSL & RSI
A professional, fully automated Expert Advisor designed specifically for high-precision SP500 index trading.
Built by Peter Dimitrov, this EA combines a reliable EMA crossover system, dynamic risk-based position sizing, RSI filtering, advanced smart trailing stop logic, and fully configurable trading sessions.
🔍 Strategy Overview
This Expert Advisor uses a robust trend-following logic based on the crossover of two EMAs (21 & 200 by default), combined with RSI filtering to avoid entering during overextended market conditions.
When a valid signal appears, the EA calculates the recent market low, determines an adaptive stop-loss distance, and automatically adjusts the lot size based on the trader’s Max Risk % setting. This ensures controlled and consistent risk management on every trade.
The integrated Smart Trailing Stop (TSL) mechanism dynamically follows price peaks and adjusts the stop-loss only when the conditions are optimal—ensuring trend trades are protected without reducing profit potential.
📈 Recommended Symbol & Timeframe
Symbol: SP500 / US500 / S&P 500 CFDs or futures
Timeframe: M30 (default)
Account Types: ECN, Raw Spread, low-spread accounts recommended
✨ Key Features
✔ EMA Crossover Trend Strategy
Entry triggered when the fast EMA crosses the slow EMA.
Uses previous bar values to avoid repainting.
Suitable for SP500 (US500) and other major indices.
✔ RSI Filter
Prevents buying into overbought conditions.
Fully configurable period & threshold.
✔ Smart Trailing Stop (TSL)
Moves the stop-loss only when new peaks are formed.
Respects broker stop levels and price precision.
Avoids micromodifications with built-in minimum movement threshold.
✔ Dynamic Risk Management
Risk per trade is automatically calculated from:
Recent market volatility
Stop-loss distance
MaxRiskPercent input
Lot size is adjusted to ensure consistent risk exposure.
✔ Configurable Trading Sessions
Trade only during specific hours (server time).
Helps avoid low-liquidity and high-spread periods.
✔ Clean, Optimized, Market-Ready Code
Uses MQL5 OOP trade library.
Handles all safety checks: indicators, margin, tick value, stop levels.
Includes protection for invalid data and abnormal conditions.
⚙ Input Parameters
| Parameter | Description |
|---|---|
| FastEMAPeriod | Fast EMA period (trend detection) |
| SlowEMAPeriod | Slow EMA period |
| RSIPeriod | RSI period |
| RSIThreshold | Avoid entries when RSI is above threshold |
| MaxRiskPercent | Automatic lot calculation per trade (percent of account balance) |
| RecentLowBars | Number of bars to scan for recent lows |
| TpMultiplier | Take profit based on stop-loss distance |
| Magic | Magic number for position tracking |
| TimeFrame | Indicator timeframe |
| StartHour / EndHour | Trading time window (server hours) |
| IsTsl | Enable/disable Smart Trailing Stop |
| MaxSpreadPoints | Maximum allowed spread in points (adaptive per symbol, e.g., higher for SP500) |
| NearCloseMinutes | Minutes before session end to block new entries |
| MaxModifyRetries | Maximum retries for modify/close per ticket within RetryWindowSec |
| RetryWindowSec | Time window (seconds) to count retries |
🧩 How It Works
Detects EMA cross (fast ↑ slow) using confirmed historical data.
Checks RSI to avoid overbought conditions.
Determines the most recent low and calculates stop-loss distance.
Computes the optimal lot size based on risk percentage.
Places a market BUY order with SL & TP.
Monitors the trade and dynamically updates stop-loss using Smart TSL.
Closes position if the reverse EMA cross appears.
🔒 Built-In Safety Features
SL/TP validation against broker stop levels
Margin and free margin checks
Tick size and tick value fallbacks
Automatic normalization of lot size
Indicator readiness validation
Weekend & low-liquidity session protection
📌 Notes
- For best results, use a broker with low spreads on the SP500 index.
- Optimization can be done on EMA periods, RSI threshold, and session hours.
- For the best performers, you can check the input settings in the screenshots.
- This Expert Advisor does not guarantee future profits.
- Тhe default input settings are based solely on historical testing and may require periodic adjustment by the user as market conditions evolve.
