19

Heikin Ashi Trading System : Amibroker AFL

Heikin-Ashi is a trend visualization technique based on Japanese candlestick charting. In-fact, Heikin-Ashi is also a type of candlestick, whose OHLC value differs from the traditional candlesticks. In Japanese, Heikin means “average” and “ashi” means “pace” . Taken together, Heikin-Ashi represents the average-pace of prices. Heikin-Ashi Candlesticks use the open-close data from the prior period and the open-high-low-close data from the current period to create a combo candlestick. In this post we would reveal a Heikin Ashi Trading System coded in Amibroker AFL. This system is optimized for NSE:Banknifty but should work well for other instruments too.

Analyzing price patterns in Heikin-Ashi charts is far more simpler and visually appealing as compared to traditional candlestick charts. See the below image:

Comparison

Image Source- Dan Valcu:CFTe

Calculating Heikin-Ashi prices

As discussed above, OHLC value for Heikin-Ashi charts differs from the traditional candlestick charts. It is calculated using the below formula:

  • HAClose = (Open+High+Low+Close)/4
    o Average price of the current bar
  • HAOpen = [HAOpen(Previous Bar) + HAClose(Previous Bar)]/2
    o Midpoint of the previous bar
  • HAHigh = Max(High, HAOpen, HAClose)
    o Highest value in the set
  • HALow = Min(Low, HAOpen, HAClose)
    o Lowest value in the set

Heikin-Ashi Trading rules

Below are the 5 important rules (from Investopedia) which should be followed while trading with Heikin-Ashi technique:

  • Green candles with no lower “shadows” indicate a strong uptrend: let your profits ride
  • Green candles signify an uptrend: you might want to add to your long position, and exit short positions.
  • One candle with a small body surrounded by upper and lower shadows indicates a trend change: risk-loving traders might buy or sell here, while others will wait for confirmation before going short or long.
  • Red candles indicate a downtrend: you might want to add to your short position, and exit long positions.
  • Red candles with no higher shadows identify a strong downtrend: stay short until there’s a change in trend.

In the next section,  we’ll go through an AFL and backtest report for this Heikin Ashi Trading System. Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.

Heikin Ashi Trading System – AFL Overview

Parameter Value
Preferred Time-frame
Daily
Indicators Used EMA
Buy Condition Formation of Heikin-Ashi green candle with Open=Low, and Close>40 period EMA of Close
Short Condition Formation of Heikin-Ashi red candle with Open=High, and Close<40 period EMA of Close
Sell Condition
  • Same as Short
  • Stop Loss Hit
  • Close<40 period EMA of Close
Cover Condition
  • Same as Buy
  • Stop Loss Hit
  • Close>40 period EMA of Close
Stop Loss 1%
Targets No fixed target
Position Size 120 Quantities
Initial Equity 200000
Brokerage 50 per order
Margin 10%

Heikin Ashi Trading System – AFL Code

Click here to download the AFL code for this system.

AFL Screenshot

Heikin Ashi AFL

Heikin Ashi Trading System – Backtest Report

Paramter Value
Fixed Position Size
Initial Capital 200000
Final Capital 1726506.44
Scrip Name NSE Banknifty
Backtest Period 01-Mar-2000 to 09-Mar-2016
Timeframe Daily
Net Profit % 763.25%
Annual Return % 13.94%
Number of Trades 276
Winning Trade % 25.36%
Average holding Period 11.88 periods
Max consecutive losses 18
Max system % drawdown -75.62%
Max Trade % drawdown -32.42%

Clearly, drawdown is on a higher side. It could be overcome with proper Risk Management strategies. Download the detailed backtest report here.

Equity Curve

Heikin Ashi Equity Curve

Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 40 and margin requirement of 10% for NSE Banknifty:

Banknifty Symbol Information

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

Related Posts

19 Comments

    • Hi Saurabh,

      Sorry this setup is exclusively for Amibroker. You may use Pi to Ami bridge to automate this strategy. Also you may post this question at http://tradingqna.com/ to get advice from Zerodha experts.

  1. Thanks for this system. Please post some other system for bank nifty intraday with low drawdown.

  2. Dear Sir,
    Many thanks & this Japanes techqnique explained very well.
    Theory & Explanation on how to use removed lots of confusion on HA approach. Your website & Your team’s positive spirit is also very good

  3. Please explain me these:
    Max system % drawdown -75.62%
    Max Trade % drawdown -32.42%

    Thanks

  4. Dear Sir, I have seen many of your postings, what i noticed is none of your afl giving winning percentage of 50% and above! Please clarify me, is it worth to follow a strategy which is giving 70 losses and 30 wins?

    And also please clarify what is the maximum winning percentage one can expect from a strategy?

    Thanks.

  5. As far as practical examples go, this site is EASILY one of the best sources of AFL knowledge on the web. I’m only a novice trader (I’m brazilian and trading local stocks) but the effort put into this blog has certainly helped immensely to surmount the steep learning curve existing in trading system development and to grasp the basics of backtesting. Congratulations and keep up the fantastic effort!

  6. Thanks for the formula. I am using Ami Broker 6. While using this formula I am getting error as Error 61: Line 20 Col:21
    “the number of format specifiers (%) does not match number of arguments passed.

    Please assist.

  7. Hi. Can u please elaborate sell condition? Does we exit long when first op=high candle formed OR when that candle itself goes below 40 ema?

Leave a Reply

Your email address will not be published.