MQL5 Wizard: Trade Signals Based on Hammer/Hanging Man Candlesticks with CCI Confirmation
Info
The MQL5 Wizard: Trade Signals Based on Hammer/Hanging Man Candlesticks with CCI Confirmation is a Expert Advisor for MetaTrader 5 that this guide details how to create expert advisors (eas) using ready-made classes provided with the metatrader 5 client terminal. This allows for rapid testing of trading ideas by creating custom trading signal classes.
Usage
This tool is typically used for automated trading on major forex pairs and gold.
Platform
This Expert Advisor works exclusively on MetaTrader 5 (both build 600+ and newer versions).
Setup
Place the downloaded file in MQL5/Experts folder via File ? Open Data Folder in MetaTrader 5.
How to Install and Use MQL5 Wizard: Trade Signals Based on Hammer/Hanging Man Candlesticks with CCI Confirmation
1. Installation: Open the "File" menu, select "Open Data Folder," navigate to MQL/Experts, paste your file, and restart the terminal.
2. Activation: Drag the EA from the Navigator onto a chart, ensure "Allow live trading" is checked in the Common tab, and verify the AutoTrading button is green.
3. Optimization: Right-click your chart, choose "Expert List," click "Properties" to adjust inputs, and save your preferred setup as a set file for future use.
4. Maintenance: Regularly check the "Experts" tab in the terminal window to monitor trade logs and potential execution errors.
Frequently Asked Questions
Q: Why is my EA not opening trades? A: Check the "AutoTrading" button, ensure "Allow live trading" is enabled, and verify your broker allows automated trading on your account type.
Q: Can I run multiple EAs on one chart? A: No, each chart can only host one active EA; however, you can open multiple charts for different currency pairs to run several EAs.
Q: What does the "smiley face" icon mean? A: A smiley face in the top-right corner of the chart indicates the EA is successfully running; a frowny face means it is disabled.
What this tool does
This guide details how to create Expert Advisors (EAs) using ready-made classes provided with the MetaTrader 5 client terminal.
Typical Use Case
This Expert Advisor excels in automated trading and technical analysis on MetaTrader 5.
Compatible Platform & Setup
This Expert Advisor works on MetaTrader 5. Place the file in the MQL5/Experts folder and restart the terminal.
Description & Settings
Related: automated trading with mq l5 wizard: crossover of two exponentially smoothed moving averages - another powerful expert for MetaTrader 5 traders.
This guide details how to create Expert Advisors (EAs) using ready-made classes provided with the MetaTrader 5 client terminal. This allows for rapid testing of trading ideas by creating custom trading signal classes.Also recommended: trade signals using reversal candlestick patterns in mql5 - similar expert with strong performance on MetaTrader 5.
The core concept involves deriving a trading signal class from a base class and overriding specific virtual methods. For this example, we focus on reversal candlestick patterns (Hammer and Hanging Man) confirmed by the CCI indicator.
To implement this, it's recommended to create a separate class derived from a candlestick pattern base class for pattern recognition. For signal confirmation, another class derived from a signal confirmation base class can be used, incorporating features like oscillator confirmation.
We will specifically examine signals based on the "Hammer" and "Hanging Man" reversal candlestick patterns, confirmed by the CCI indicator. The trading signal module is based on a specific class, demonstrating its use for creating candlestick pattern-based trade signals.
Hammer and Hanging Man Reversal Candlestick Patterns
Hammer
The "Hammer" is a candlestick pattern with a small body and a long lower wick, typically formed after a downward price movement, signaling a potential end to a bearish trend. While the body color is not critical, a bullish hammer suggests stronger bullish potential. The body often forms near the previous candle's low. A longer lower wick and shorter upper wick increase the pattern's reversal potential.
The recognition of the "Hammer" pattern is implemented in the `checkpatternhammer()` method.
Hanging Man
The "Hanging Man" is a candlestick with a small body and a long lower wick, formed after an upward price movement, indicating a potential end to a bullish trend. Similar to the hammer, the body color is less important, but a bearish candle suggests higher bearish potential. The body often forms near the previous candle's high. A longer lower wick and shorter upper wick enhance the pattern's reversal potential.
The recognition of the "Hanging Man" pattern is implemented in the `checkpatternhangingman()` method.
Trade Signals Confirmed by CCI Indicator
Trading signals for opening long or short positions must be confirmed by the CCI indicator. For a long position, the CCI value should be greater than -50, and for a short position, it should be less than 50.
Position closing depends on CCI values. Positions can be closed in two scenarios:
1. The CCI line reaches the opposite critical level (80 for long positions, -80 for short positions).
2. The reverse signal is not confirmed (when CCI reaches levels of -80 for long positions and 80 for short positions).
Open Long Position / Close Short Position
The formation of a "Hammer" pattern must be confirmed by the CCI indicator: CCI(1) < -50 (the CCI value of the last completed bar must be less than -50).
A short position should be closed if the CCI has crossed the critical level of -80 upwards or the critical level of 80 downwards.
Open Short Position / Close Long Position
The formation of a "Hanging Man" pattern must be confirmed by the CCI indicator: CCI(1) > 50 (the CCI value of the last completed bar must be greater than 50).
A long position should be closed if the CCI has crossed the -80 or 80 levels downwards.
Creating an Expert Advisor Using MQL5 Wizard
The custom signal class (e.g., `ch_hm_cci`) is not part of the standard library. To use it, download the corresponding `.mqh` file and save it in the `client_terminal_data_folder\mql5\Include\Expert\Signal\MySignals` directory. The `candlepatterns.mqh` file should also be placed similarly. After restarting MetaEditor, these files will be available in the MQL5 Wizard.
To create an Expert Advisor, launch the MQL5 Wizard. Specify the desired name for the Expert Advisor and its general properties.
Next, select the trading signal modules to be used. In this case, we will use only one module: "Signals based on Hammer/Hanging Man confirmed by CCI".
After adding the signal module, you can configure trailing stop properties. For this example, we will not use trailing stops.
Regarding money management, we will use "Trading with fixed trade volume".
Pressing the "Finish" button will generate the Expert Advisor code, saved as `Expert_AH_HM_CCI.mq5` in the `terminal_data_folder\mql5\Experts\` directory.
The default input parameters of the generated Expert Advisor, such as `signal_thresholdopen` and `signal_thresholdclose`, allow for specifying threshold levels for opening and closing positions. These values are influenced by the number of signal modules used and the averaging of votes. For instance, with one main module and one trade signal module, the thresholds need adjustment (e.g., `signal_thresholdopen` to 40 and `signal_thresholdclose` to 20) to account for the combined vote results.
The `signal_stoplevel` and `signal_takelevel` input parameters are set to 0, indicating that position closing will occur solely based on the defined closing conditions.
History Backtesting Results
Backtesting was performed on historical data (EURUSD H1) for the period 2010.01.01 - 2011.03.16, with CCI period set to 25 and MA period to 5. A fixed volume of 0.1 was used, and no trailing stop algorithm was applied.
The optimal set of input parameters can be determined using the Strategy Tester within MetaTrader 5. The generated Expert Advisor code is provided as `Expert_AH_HM_CCI.mq5`.
You may also like: mql5 wizard: trade signals with dark cloud cover/piercing line and rsi confirmation - excellent alternative for expert users on MetaTrader 5.
Source Code
#property copyright "robotfx"
#property link "https://robotfx.org"
#property version "1.00"
#include <expert\expert.mqh>
#include <expert\signal\mysignals\ach_hm_cci.mqh>
#include <expert\trailing\trailingnone.mqh>
#include <expert\money\moneyfixedlot.mqh>
input string expert_title ="expert_ah_hm_cci"; // document name
ulong expert_magicnumber =20635; //
bool expert_everytick =false; //
.......
⚠ Limitations & Risk Warning
- This tool is provided for educational and testing purposes only.
- Past performance does not guarantee future results.
- Trading involves substantial risk of loss. Use on a demo account first.
- Results may vary depending on market conditions, broker, and settings.
- We recommend thorough backtesting and forward testing before using with real funds.