OPEN-SOURCE SCRIPT

Heikin-Ashi Non-Repainting Strategy [PineIndicators]

369
The Problem with Heikin-Ashi Strategies in TradingView
Many traders rely on Heikin-Ashi candles to smooth price movements and identify trends more clearly. However, most Heikin-Ashi-based strategies in TradingView suffer from a major issue: repainting.

Why Do Heikin-Ashi Strategies Repaint?
Heikin-Ashi candles in TradingView are calculated dynamically based on historical bars. When used for strategy execution:
  • Past Heikin-Ashi candles change based on new data. This makes historical backtesting unreliable.
  • Trades appear better than they actually were. Since Heikin-Ashi averages past prices, the strategy often "knows" future movements that wouldn’t be available in real-time.
  • Live trading results differ from backtesting. The strategy might execute trades in a way that isn’t reproducible when running live.


Solution: Non-Repainting Heikin-Ashi Calculation
This strategy emulates Heikin-Ashi candles without repainting, ensuring:
  • Stable past price action. Once a candle closes, its values do not change.
  • Consistent strategy performance. The backtest results align with live market execution.
  • Accurate trade signals. Entries and exits are based on confirmed Heikin-Ashi trends, rather than fluctuating, recalculated values.


Additionally, this strategy supports inverted trades, allowing traders to reverse the standard logic, making bullish setups trigger shorts and bearish setups trigger longs.

How the Non-Repainting Heikin-Ashi Strategy Works
1. Manual Heikin-Ashi Calculation Without Repainting
Instead of using TradingView’s built-in Heikin-Ashi option (which repaints), this strategy manually calculates Heikin-Ashi values:
  • Close: The average of open, high, low, and close.
  • Open: A rolling average of the previous Heikin-Ashi open and close.
  • High/Low: The highest and lowest values among price components.


These calculations are fixed at the time of each bar’s close, ensuring that past values remain unchanged.

2. Trend Confirmation with Consecutive Candles
To enter a trade, the strategy requires a defined number of consecutive bullish or bearish Heikin-Ashi candles:
  • Long Entry: After X consecutive bullish Heikin-Ashi candles.
  • Short Entry: After X consecutive bearish Heikin-Ashi candles.
  • Exit Conditions: Opposite candle sequences trigger exits.


By requiring multiple candles for confirmation, false signals are filtered out, improving reliability.

3. Inverted Trade Mode (Optional)
For traders who want to trade against Heikin-Ashi trends, an inversion mode flips the trade logic:
  • Bullish sequences trigger short trades.
  • Bearish sequences trigger long trades.


This can be particularly effective in range-bound markets where counter-trend strategies perform better.

Trade Entry & Exit Conditions
This strategy allows traders to select from three trade modes:
  • Long & Short: Takes both long and short trades.
  • Only Long: Restricts trading to long positions.
  • Only Short: Restricts trading to short positions.


Entry Conditions
  • Long Entry:

    A defined number of consecutive bullish Heikin-Ashi candles confirm an uptrend.
    Trade mode allows long trades.
  • Short Entry:

    A defined number of consecutive bearish Heikin-Ashi candles confirm a downtrend.
    Trade mode allows short trades.

Exit Conditions
  • Long Exit: A defined number of bearish Heikin-Ashi candles indicate trend reversal.
  • Short Exit: A defined number of bullish Heikin-Ashi candles indicate trend reversal.


If the inversion mode is enabled, these rules are reversed.

Visualization: Transparent Heikin-Ashi Candles
This strategy overlays custom Heikin-Ashi candles onto the chart without hiding traditional price data. The candles are:
  • Green for bullish trends.
  • Red for bearish trends.
  • Transparent to keep chart visibility clear (optional setting).


For traders who prefer to focus only on Heikin-Ashi, an option is available to hide standard candles.

Why This Strategy is More Reliable Than Standard Heikin-Ashi Strategies
1. No Repainting – Accurate Trade Execution
  • Past data remains unchanged, ensuring consistent backtesting and live results.
  • Entries and exits are based on confirmed trends, not shifting historical data.


2. Filters False Signals with Consecutive Candles
  • Requires multiple Heikin-Ashi candles to confirm a trend.
  • Reduces whipsaw trades and prevents overtrading.


3. Supports Both Trend-Following and Inversion Strategies
  • Works with trends (default mode).
  • Can be used against trends (inverted mode).
  • Traders can optimize settings for different market conditions.


Performance on SPX 4H – Long Only Mode
When tested on SPX (S&P 500) 4-hour charts, the strategy in Long Only mode has shown strong performance:
  • Captures long-term bullish trends without frequent reversals.
  • Avoids whipsaws by filtering out weak signals.


For traders focusing on high-probability long entries, this setting is recommended for SPX and similar large-cap indices.

Customization Options
This strategy includes adjustable parameters:
  • Number of Candles for Entry → Set how many consecutive Heikin-Ashi candles confirm a trade.
  • Number of Candles for Exit → Define exit signal requirements.
  • Trade Mode → Choose between Long & Short, Long Only, or Short Only.
  • Inverted Trade Mode → Flip trade logic for contrarian strategies.
  • Hide Standard Candles → Option to remove price candles for cleaner visualization.


Considerations & Limitations
  • Not Ideal for Fast Scalping. This strategy is best suited for swing trading and trend-following.
  • Requires Market Trends. Works best in markets with clear uptrends or downtrends.
  • Shorter Timeframes May Need Optimization. For intraday trading, adjusting entry/exit thresholds may improve performance.


Conclusion
The Heikin-Ashi Emulation with Thresholds Strategy provides a non-repainting, structured approach to Heikin-Ashi-based trading. By:
  • Eliminating repainting issues.
  • Using consecutive candles for confirmation.
  • Supporting trend-following & reversal trading.

this strategy allows traders to use Heikin-Ashi with confidence and accuracy.

Great performance has been seen on SPX 4H long-only inverted trades (See backtest).

Please BOOST and COMMENT with your thoughts!

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.