forexeasourcecodes
MQL4 SOURCE CODE EA ANGRY SCALPER
MQL4 SOURCE CODE EA ANGRY SCALPER
Couldn't load pickup availability
The "Angry Scalper" Expert Advisor (EA) for MetaTrader 4 (MT4) implements a **grid trading strategy** with elements of martingale and technical indicator-based decision-making. It uses the Relative Strength Index (RSI) for initial trade entries and the Commodity Channel Index (CCI) for trade closure under certain conditions, combined with dynamic or fixed pip steps for placing additional grid orders. Below explain how the EA trades, breaking down its logic, entry/exit rules, and risk management features.
Overview of Trading Strategy
The EA is designed to trade on a single symbol (the chart it’s attached to) and operates as a grid-based scalping system. It opens a series of buy or sell orders at predefined price intervals (grid levels) when the market moves against the initial position, increasing lot sizes exponentially (martingale approach). The goal is to capture profits when the market reverses, covering losses from earlier trades. The EA uses RSI to determine initial trade direction and CCI to close trades under specific conditions, with optional features like trailing stops, equity-based stops, and trade timeouts.
Key Components of the Trading Logic
1. **Input Parameters**:
- **LotExponent**: Multiplier for lot size in subsequent grid orders (default: 2.0). For example, if the initial lot is 0.01, the next order could be 0.02, then 0.04, etc.
- **DynamicPips**: If true, calculates the pip step dynamically based on price volatility; otherwise, uses `DefaultPips` (default: 12).
- **Glubina** and **DEL**: Used for dynamic pip step calculation, determining the lookback period (24 bars) and divisor (3) for volatility-based spacing.
- **Lots**: Initial lot size (default: 0.01).
- **lotdecimal**: Lot precision (default: 2, for micro lots like 0.01).
- **TakeProfit**: Profit target in points (default: 20).
- **Stoploss**: Stop loss in points (default: 500).
- **TrailStart** and **TrailStop**: Trailing stop parameters (default: 10 points each).
- **RsiMinimum** and **RsiMaximum**: RSI thresholds for trade entries (default: 30 and 70).
- **MagicNumber**: Unique identifier for the EA’s trades (default: 2222).
- **MaxTrades**: Maximum number of simultaneous open orders (default: 10).
- **UseEquityStop** and **TotalEquityRisk**: If enabled, closes all trades if losses exceed a percentage of equity (default: 20%).
- **UseTrailingStop**: Enables trailing stops (default: false).
- **UseTimeOut** and **MaxTradeOpenHours**: Closes trades after a specified duration (default: 48 hours, disabled by default).
- **MaxRetries**: Maximum retries for order placement (default: 100).
- **slip**: Slippage tolerance in points (default: 3).
2. **Initialization**:
- The `init()` function calculates the spread for the current symbol to adjust price calculations.
- Initializes `PrevEquity` to track account equity for equity-based stops.
3. **Dynamic Pip Step Calculation**:
- If `DynamicPips` is true, the EA calculates the pip step (`PipStep`) based on the price range over the last `Glubina` bars (default: 24):
- Finds the highest and lowest prices over the lookback period.
- Calculates `PipStep = (High - Low) / DEL / Point`, normalized to an integer.
- Ensures `PipStep` is within bounds (`DefaultPips/DEL` to `DefaultPips*DEL`).
- If `DynamicPips` is false or `DEL` is zero, uses `DefaultPips` (default: 12).
4. **Trade Entry Logic**:
- The EA operates in two scenarios: initial trade entry (no open trades) and grid trade entry (when trades are already open).
- **Initial Trade Entry** (when no trades are open, `tradeCount CurrCl`) and RSI is above `RsiMinimum` (default: 30), opens a sell order at the current Bid price.
- **Buy**: If the previous bar’s close is lower than the current bar’s close (`PrevCl = PipStep * Point`, opens a new buy order.
- For sell trades: If `Bid - LastSellPrice >= PipStep * Point`, opens a new sell order.
- Lot size increases exponentially: `Lots * MathPow(LotExponent, NumOfTrades)`, where `NumOfTrades` is the current number of open trades.
- Orders include stop loss and take profit.
5. **Trade Exit Logic**:
- **Take Profit**: Each order has a take profit set at `TakeProfit` points (default: 20) from the average price of open trades.
- **Stop Loss**: Each order has a stop loss set at `Stoploss` points (default: 500) from the average price.
- **CCI-Based Closure**:
- Uses a 55-period CCI on a 15-minute timeframe.
- Closes all trades if:
- For sell trades (`ShortTrade`): CCI > 500.
- For buy trades (`LongTrade`): CCI 30, it opens a sell order with lot size 0.01 (assuming `Lots = 0.01`).
- If the current bar closes higher and RSI `RsiMinimum = 30`). The EA opens a sell order at Bid (e.g., 1.1200) with lot size 0.01, stop loss at 1.1700 (500 points), and take profit at 1.1180 (20 points).
- **Step 2**: Price rises to 1.1212 (12 points against the position). The EA opens another sell order at 1.1212 with lot size 0.02.
- **Step 3**: The EA recalculates the average price (weighted by lot sizes) and adjusts stop loss and take profit for all trades. If price continues rising, more sell orders are placed at 1.1224, 1.1236, etc., up to 10 trades.
- **Step 4**: If CCI exceeds 500, all trades are closed. Alternatively, if the price drops and hits the take profit (e.g., 20 points below the average price), trades close in profit. If losses exceed 20% of equity, all trades are closed (if `UseEquityStop` is true).
### Risk Considerations
- **High Risk**: The martingale strategy increases lot sizes exponentially, which can lead to large drawdowns or account blowouts if the market moves significantly against the position.
- **Stop Loss**: The default stop loss (500 points) is large, meaning significant losses can accumulate before closure.
- **MaxTrades**: Limiting trades to 10 helps, but the exponential lot increase can still strain account equity.
- **Broker Requirements**: Requires a broker with low spreads and high leverage to handle multiple orders and large lot sizes.
- **Market Conditions**: Performs best in ranging markets; trending markets can lead to substantial losses.
### Recommendations for Use
1. **Backtesting**: Test the EA in MT4’s Strategy Tester on historical data for your chosen symbol and timeframe to evaluate performance and optimize parameters (e.g., `PipStep`, `LotExponent`, `TakeProfit`).
2. **Demo Account**: Run the EA on a demo account to observe its behavior in live market conditions before risking real capital.
3. **Risk Management**:
- Reduce `LotExponent` (e.g., to 1.5) to slow lot size growth.
- Lower `MaxTrades` to limit exposure.
- Set a smaller `Stoploss` to cap losses per trade.
- Enable `UseEquityStop` to protect against catastrophic losses.
4. **Parameter Optimization**:
- Adjust `RsiMinimum` and `RsiMaximum` to align with the symbol’s volatility.
- Fine-tune `Glubina` and `DEL` for dynamic pip steps based on market conditions.
- Test CCI thresholds (currently 500/-500) to ensure they suit the trading strategy.
5. **Broker Compatibility**: Ensure your broker supports micro lots (`lotdecimal = 2`) and allows multiple open orders without restrictions.
### Potential Improvements
- **Maximum Lot Size**: Add a cap to prevent excessively large lots in the grid.
- **Dynamic Take Profit/Stop Loss**: Adjust take profit and stop loss based on market volatility or ATR.
- **Additional Filters**: Incorporate other indicators (e.g., moving averages) to confirm trade direction and reduce false entries.
- **Logging**: Enhance logging to track why trades are opened/closed for better debugging and optimization.
### Summary
The "Angry Scalper" EA trades using a grid strategy with martingale lot sizing, entering trades based on RSI and price movement, and exiting based on take profit, stop loss, CCI signals, equity stops, or timeouts. It places buy or sell orders at fixed or dynamic intervals, increasing lot sizes exponentially to recover losses. However, this approach is high-risk due to the potential for large drawdowns. Thorough testing and conservative parameter settings are crucial before using it in a live account.
Share
