Strategy · Pine Script v5 · On the chart

Heikin Ashi with Session Wicks Strategy

by g-moe· code credited to goodgains

This strategy plots smoothed Heikin Ashi candlesticks directly on the price chart.

View on GitHub

Repaints

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code101
Settings17inputs
LicenceNone statedfile: MPL-2.0
Last update5 months ago27 May 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.

Source Code

101 lines of Pine Script v5 from Tradingview/heikin-ashi-session-wicks-strategy.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

heikin-ashi-session-wicks-strategy.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © goodgains


//@version=5
strategy("Heikin Ashi with Session Wicks Strategy", overlay = true)

// @keywords: heikin-ashi, smoothed-candles, cci-crossover, stochastic-kd, strategy-long-short, ema-smooth, multi-timeframe, trading-session, bull-bear-ha, entry-exit, cross-above, cross-below, ha-candle-plot, trend-reversal, session-filter, strategy-start, long-trades, short-trades, momentum-filter, wick-strategy

ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

// CCI
cci_timeframe = input.timeframe('', title = 'Timeframe to Use', group = 'CCI Settings')
cci_length = input.int(20, minval=1, title = 'CCI Length', group = 'CCI Settings')
cci_source = input.source(hlc3, title = 'CCI Source', group = 'CCI Settings')
cci_long = input.int(60, title = 'CCI Long Cross Above', group = 'CCI Settings')
cci_short = input.int(-60, title = 'CCI Short Cross Below', group = 'CCI Settings')
bars_for_cross = input.int(10, title = 'Max Bars For Cross', group = 'CCI Settings')

cci  = request.security(syminfo.tickerid, cci_timeframe, ta.cci(cci_source, cci_length)[1], lookahead = barmerge.lookahead_on)

cci_long_cross = bar_index - ta.valuewhen(ta.crossover(cci, cci_long), bar_index, 0)
cci_short_cross = bar_index - ta.valuewhen(ta.crossunder(cci, cci_short), bar_index, 0)

// Stoch
stoch_timeframe = input.timeframe('', title = 'Timeframe to Use', group = 'Stoch Settings')
periodK = input.int(14, title="%K Length", minval=1, group = 'Stoch Settings')
smoothK = input.int(1, title="%K Smoothing", minval=1, group = 'Stoch Settings')
periodD = input.int(3, title="%D Smoothing", minval=1, group = 'Stoch Settings')

k = request.security(syminfo.tickerid, stoch_timeframe, ta.sma(ta.stoch(close, high, low, periodK), smoothK), lookahead = barmerge.lookahead_on)
d = request.security(syminfo.tickerid, stoch_timeframe, ta.sma(k, periodD), lookahead = barmerge.lookahead_on)


// CHART Heikin-ashi
len=input.int(10, title = "Length 1", group = 'Chart HA Settings')
o=ta.ema(open,len)
c=ta.ema(close,len)
h=ta.ema(high,len)
l=ta.ema(low,len)

var float haopen = 0.00
haclose = (o+h+l+c)/4
haopen := na(haopen[1]) ? (o + c)/2 : (haopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen,haclose))
halow = math.min(l, math.min(haopen,haclose))

len2=input(10,  title = "Length 2", group = 'Chart HA Settings')
o2=ta.ema(haopen, len2)
c2=ta.ema(haclose, len2)
h2=ta.ema(hahigh, len2)
l2=ta.ema(halow, len2)

col= o2>c2 ? color.red : color.green
chartha_bull = c2 >= o2
chartha_bear = c2 < o2

plotcandle(o2, h2, l2, c2, title="heikin smoothed", color=col)
// CHART Heikin-ashi

// --STRATEGY INPUTS-- //
strategy_start = input.time(timestamp("01 January 2020 00:00:00 UTC-5"), "Strategy Start Date", group = "StrategySettings", inline = '1')
use_trading_hours = input.bool(false, title = "Use Trading Hours", tooltip = "This is ignored if the chart timeframe is greater than or equal to the daily timeframe.", group = "StrategySettings", inline = '2')
trading_time = input.session("0930-1600", title = " ", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "StrategySettings", inline = '2')
trading_hours_cond = not use_trading_hours or time("",trading_time, "America/New_York")

long_trades = input.bool(true, title = "Long Trades", tooltip = "Do we want to take long trades?" , group = "StrategySettings", inline = '3')
short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to take short trades?" , group = "StrategySettings", inline = '4')

long_entry = long_trades and trading_hours_cond and chartha_bull and k > d and cci_long_cross <= bars_for_cross
long_exit = long_trades and chartha_bull[1] and not chartha_bull

short_entry = short_trades and trading_hours_cond and chartha_bear and k < d and cci_short_cross <= bars_for_cross
short_exit = short_trades and chartha_bear[1] and not chartha_bear

past_strategy_start_date = time >= strategy_start ? true : false
// --STRATEGY INPUTS-- //


// --ORDERS-- //
if past_strategy_start_date
    if long_exit
        strategy.close("LE", comment = 'LX')

    if short_exit
        strategy.close("SS_E", comment = 'SS_X')

    if long_entry
        strategy.entry("LE", strategy.long)

    if short_entry
        strategy.entry("SS_E", strategy.short)


// --ORDERS-- //

Overview

Heikin Ashi with Session Wicks Strategy filters entries using CCI and Stochastic crossovers calculated on a separate higher timeframe. Long signals trigger on CCI crossing above 60 and Stochastic crossing above its signal line, while short signals trigger on CCI crossing below -60 and Stochastic crossing below. Trades respect a configurable trading session and can be enabled for longs or shorts. A fixed start date filters the strategy. No stop loss, take profit, or position sizing is applied by default. It draws only on the chart and incorporates multi-timeframe data with lookahead.

Details

Published by

g-moe on GitHub

Code credit

goodgains, as written in the script's header

Type

Strategy, Pine Script v5

Draws

On the price chart

Category

Candlestick patterns, Sessions & time, Oscillators & momentum

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Signals can change on the live bar or after it closes (repainting)
  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time
  • The strategy enters trades without a stop loss

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Timeframe to Usetimeframecci_timeframe
CCI Lengthint20cci_length
CCI Sourcesourcehlc3cci_source
CCI Long Cross Aboveint60cci_long
CCI Short Cross Belowint-60cci_short
Max Bars For Crossint10bars_for_cross
Timeframe to Usetimeframestoch_timeframe
%K Lengthint14periodK
%K Smoothingint1smoothK
%D Smoothingint3periodD
Length 1int10len
Length 2int10len2
Show all 17 settings
SettingTypeDefaultVariable
Strategy Start Datetimetimestamp("01 January 2020 00:00:00 UTC-5")strategy_start
Use Trading Hoursboolfalseuse_trading_hours
session0930-1600trading_time
Long Tradesbooltruelong_trades
Short Tradesbooltrueshort_trades
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

330 stars

Improvising [Alorse] is a price-chart strategy that looks for a one-bar candle reversal filtered by a 10-period EMA, a 14-period RSI, and a rising or falling MACD. Longs require a bearish bar followed by a bullish close above the EMA, RSI below 65, and a risin

Strategy v5 Oscillators & momentumMoving averages
Updated 2 months ago · None stated GitHub repository of Improvising [Alorse]
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
106 stars

This strategy trades the three-candle strike pattern filtered by trend direction and time sessions. It calculates market regime using linear regression and exponential or smoothed moving averages to distinguish between ranging and trending conditions. Risk man

Strategy v5 Candlestick patternsTrend
Updated 2 years ago · GPL-3.0 GitHub repository of 3 Candle Strike Strategy
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy
43 stars

Donald - AI Futures is a price-chart strategy that estimates inner and outer high-low zones and a smoothed close with rational quadratic kernel regression. It builds bullish and bearish momentum signals, optionally compares volume with a volume-weighted moving

Strategy v5 Oscillators & momentumSMC / ICT / price action Repaints
Updated 2 years ago · None stated GitHub repository of Donald - AI Futures

Turtle MACD Time-Zone Filter

by skywalker0803r
42 stars

This strategy enters long when price closes above the prior Donchian high and short when it closes below the prior Donchian low, only while flat and inside a Taipei-hour window. It exits on a MACD histogram reversal or through an ATR stop and a percentage take

Strategy v5 BreakoutOscillators & momentum
Updated 2 months ago · None stated GitHub repository of Turtle MACD Time-Zone Filter

More strategys

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers