Introduction
Heiken Ashi Naïve is a MetaTrader expert advisor based on Heiken Ashi charting system through the platform's standard indicator by the same name. The employed trading system is naive in a way that it interprets only two latest Heiken Ashi candles and does not apply any complex pattern analysis. The only trick is that the expert advisor trades against the supposed trend direction, confirmed by current Heiken Ashi setup. Its biggest advantage is that it has no input parameters to optimize and curve-fit to the past data. Optional ATR-based position sizing is available for improved money management. There are two versions of the EA: a plain one and one with Z-Score optimization applied. The expert advisor (with and without Z-Score optimization) is available for both MT4 and MT5 versions of the platform.
Heiken Ashi
Heiken Ashi (or Heikin Ashi, from Japanese 平均足) is an alternative technique of representing the usual candlestick charts for the purpose of trading. Unlike with traditional Japanese candles, it is impossible to read the actual price levels (Open, High, Low and Close) on Heiken Ashi chart, but it is easier to spot trend developments and reversals. Rising Heiken Ashi candles are usually plotted as white ones, and the falling — as red ones. Similar to the standard candles, Heiken Ashi show wicks. Neither direction of a candle, nor the length of its wicks point to actual price levels, but rather should be considered in relation to other Heiken Ashi candles in the close proximity.
The switch of colors means a change of trend: red to white — a bearish trend reversal, white to red — a bullish trend reversal. Increasing candle body length signals strengthening of trend. Decreasing — signals weakening. Lower wicks on white candles and upper wicks on red candles signal volatility and trend instability. Lack of such wicks indicates a definite and clear trend.
Calculation Rules
The following rules are used to calculate Heiken Ashi candle levels:
- HA_Open = (previous HA_Open + previous HA_Close) / 2
- HA_Low = minimum(Low, HA_Open, HA_Close)
- HA_High = maximum(High, HA_Open, HA_Close)
- HA_Close = (Open + High + Low + Close) / 4
Where:
- HA_Open, HA_High, HA_Low and HA_Close — Heiken Ashi candle levels.
- Open, High, Low and Close — normal candle levels.
- The levels of the initial HA candle are equal to respective levels of the original candle.
Heiken Ashi Chart
The chart that you see below demonstrates the Heiken Ashi candle technique, showing both trending and ranging periods. The initial uptrend (white) becomes weak with Heiken Ashi doji and turns red for four candles. Only one candle (second) in this downtrend qualifies for a strong bearish trend according to Heiken Ashi rules outlined above. The renewed bullish trend shows a period of weakness (short-bodied candles with downside wicks) but then returns to its strength. A small red correction goes rather deep and is signaled as such by the long-bodied candles without upper wicks. Without a clear reversal signal, a new upward trend ensues. It was followed by a plateau with a chaos of red/white colors, which ended in a long downward trend. A small correction consisting of five white with one red candle in a middle did not stop the whole trend going south till the end of the chart.
Naturally, such an indicator looks rather promising to traders who wish to trade on trends and their reversals.
Trading Strategy
Heiken Ashi Naïve expert advisor uses a rather simple, yet not very obvious method to trade with Heiken Ashi candles.
The following entry signals are used:
- Sell if the latest completed HA candle is bullish, its body is longer than previous candle's body, previous candle is also bullish, and latest candle has no lower wick.
- Buy if the latest completed HA candle is bearish, its body is longer than previous candle's body, previous candle is also bearish, and latest candle has no upper wick.
If there exists an open position in an opposite direction when a signal arrives, the position is closed. If the existing position is in the same direction as the signal, the latter is ignored.
The following exit signals are used to close trades before a new entry signal arrives:
- Exit short position if the latest completed HA candle is bearish, previous candle is also bearish, and the latest candle has no upper wick.
- Exit long position if the latest completed HA candle is bullish, previous candle is also bullish, and the latest candle has no lower wick.
As you can see, the expert advisor uses the inverted logic in its trading strategy. It goes long when the Heiken Ashi system points at a rather strong bearish trend, and it goes short when it is a bullish rally according to Heiken Ashi. The trick here is that it tries to catch reversals as early as possible.
You can switch it to use the direct trading strategy by setting the Inverted input parameter to false.
Trade Examples
The chart screenshot from the strategy backtest on EUR/JPY is shown below. There are six completed trades:
- The first position is bearish (shown with a red arrow) and lasts for 8 candles until the new position is entered following bullish entry signal generation.
- The second position is bullish (shown with a blue arrow) and is a big loser. The downtrend signaled by Heiken Ashi turns out to be a lasting one, so the advisor's system fails here.
- The third position is a short-term bearish one (second red arrow). It lasts only 3 days and is quite profitable.
- The fourth position is a short-term bullish one (second blue arrow) and is even more profitable.
- The fifth position is another short-term sell (third red arrow). It is the most profitable trade of the six shown in these examples.
- The sixth position is long (third blue arrow). It is very profitable and last for long enough to live through several white candles, which fail to trigger exit conditions for the bullish trade.
Position Sizing
Heiken Ashi Naïve expert advisor uses the same advanced position sizing system as the Ichimoku Chikou Cross expert advisor. It is capable of both fixed position size and ATR-based fixed fractional position size.
Z-Score Optimization
The second version of this expert advisor has Z-Score optimization implemented in its algorithm. Z-Score optimization is based on the intrinsic parameter of some Forex strategies. Basically, Z-Score value tells us if there is any correlation between the trade outcomes of the given strategy. Large positive Z-score (like the one of Heiken Ashi Naïve on EUR/JPY @ D1) means that the winning trade is likely to be followed by a losing one, and that the losing trade will probably be followed by a winning one. Large negative Z-score would mean that winning trades are often followed by more winning trades, while losing trades frequently follow the same losing trades. Obviously, such metric can be used to optimize a trading strategy or an expert advisor.
Heiken Ashi Naïve with Z-score optimization stops trading following a profitable trade. It then switches to a virtual trading mode, where it calculates the trades, but does not actually send any orders to MetaTrader sever. Once a losing virtual trade is encountered, the EA switches back to real trading mode and continues normal operation. This expert advisor is also capable of saving and loading all the virtual trading data from file, preventing Z-score optimization malfunction due to software or hardware failures.
Backtest Results
The backtest of the Heiken Ashi Naïve expert advisor was performed on the period from January 1, 2013, through April 13, 2022 (9 years) on the EUR/USD D1 chart.
When fixed position volume of 0.1 standard lot has been used, the resulting net profit was $2,920.31 on $10,000 starting account balance with the maximum relative drawdown of 18%.
With ATR-based position sizing enabled (ATR period = 20; ATR multiplier = 2; 2% risk tolerance), the resulting net profit fell to $1,025.37 on the same $10,000 starting account balance, while the maximum relative drawdown 22.4%.
Backtesting Z-Score Optimized EA
Z-Score optimized version of Heiken Ashi Naïve expert advisor was backtested on the same data as the original version. The performance resulted in $421.63 profit and 9.5% relative drawdown for a fixed position size (0.1 standard lot). When using ATR-based position sizing, the EA has shown $62.44 with 8.2% drawdown.
As you can see, there is little point in using a Z-Score optimized version of this expert advisor unless you really need to obtain a lower drawdown value. Z-Score version makes only 104 trades compared to 311 trades of the original version.
Input Parameters
Main
- Inverted (default = true) — if true, the EA trades the inverted Heiken Ashi strategy — it sells on bullish signals and buys on bearish signals.
Money management
- Lots (default = 0.1) — basic lot size for fixed position sizing. Used when MM = false.
- MM (default = false) — if true, ATR-based position sizing is enabled.
- ATR_Period (default = 20) — the period of the ATR indicator, which is used for position size calculation. Works only if MM = true.
- ATR_Multiplier (default = 1) — a value, by which the ATR indicator value will be multiplied. Works only if MM = true.
- Risk (default = 2) — risk tolerance in percentage of account balance/equity. Works only if MM = true. This input parameter is ignored if UseMoneyInsteadOfPercentage is set to true.
- FixedBalance (default = 0) — if set to non-zero value, it is used instead of account balance/equity for position size calculation. Works only if MM = true.
- MoneyRisk (default = 0) — risk tolerance in account currency. Works only if MM = true. Requires UseMoneyInsteadOfPercentage to be set to true.
- UseMoneyInsteadOfPercentage (default = false) — if true, position size is calculated based on risk amount given in account currency (MoneyRisk) instead of balance/equity percentage risk (Risk). Works only if MM = true.
- UseEquityInsteadOfBalance (default = false) — if true, position size is calculated based on account equity instead of balance. Works only if MM = true. Ignored if UseMoneyInsteadOfPercentage = true.
Miscellaneous
- OrderComment (default = "HAN") — the commentary for positions opened by this EA.
- Slippage (default = 100) — the acceptable price slippage in pips.
- Magic (default = 152207122013) — the order magic number to filter positions opened by this EA. Used only in MT4.
- Mute (default = false) — if true, EA will produce no output regarding virtual trading events. This input parameter is present only in Z-Score optimized version.
- FileName (default = "HAN_vt.dat") — the name of the file used by the EA to store virtual trading data. This input parameter is present only in Z-Score optimized version.
MiniFAQ
What is the average win/loss size generated by this EA?
Its backtest on EUR/USD @ D1 showed an average losing trade of 136 pips and an average winning trade of 83 pips. The version with Z-Score optimization has shown 129 pips average loss and 76 pips for average profitable position.
How often does this EA trade?
On daily EUR/USD chart (default setting), this EA will trade about 3 times a month on average. Z-Score version of Heiken Ashi Naïve will trade about 11 times a year.
What is the difference between the versions for MT4 and for MT5?
MT5 version will interfere with positions of other expert advisors on the same currency pair. MT4 will use Magic number to avoid that.
Did it show profitable results on any other currency pairs?
Some other currency pairs show insignificant profit, which are spoiled by big drawdowns. It looks like only EUR/USD has some trading characteristics that are captured by this expert advisor.
Did you optimize the input parameters of this expert advisor?
There are no inputs to optimize unless you consider currency pair and timeframe as inputs.
Download (ver. 1.03, 2022-09-30)
Normal Version
Download Heiken Ashi Naïve for MT4 Download zipped Heiken Ashi Naïve for MT4 Download Heiken Ashi Naïve for MT5 Download zipped Heiken Ashi Naïve for MT5
Z-Score Optimized Version
Download Heiken Ashi Naïve with Z-Score optimization for MT4 Download zipped Heiken Ashi Naïve with Z-Score optimization for MT4 Download Heiken Ashi Naïve with Z-Score optimization for MT5 Download zipped Heiken Ashi Naïve with Z-Score optimization for MT5
Discussion
Warning! Before you ask basic questions regarding installation of the expert advisors, please, read this MT4 Expert Advisors Tutorial to get the elementary knowledge on handling them.
Do you have your own trading results or any other remarks regarding this expert advisor?
Discuss Heiken Ashi Naïve with other traders and MQL programmers on the experts forums.
Changelog
1.03 - 2022-09-30
- Added Inverted input parameter to let traders easily switch between direct trading signals and inverted.
1.02 - 2022-04-13
- Removed the LotDigits input parameter — it is now calculated automatically.
- Improved the clarity of input parameters' descriptions and error messages.