Strategy · Pine Script v5 · On the chart

Heikin Ashi with Session Wicks Strategy

by g-moe· code credited to goodgains

This strategy calculates double-smoothed Heikin Ashi candles and plots them directly on the price chart alongside a smoothed Relative Strength Index.

View on GitHub

GitHub stars3on the repository
Pine versionv5runs as is
Lines of code143
Settings21inputs
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

143 lines of Pine Script v5 from Tradingview/heikin-ashi-session-wicks-strategy-v2.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-v2.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, margin_long=100, margin_short=100)

// @keywords: heikin-ashi, smoothed-candles, chart-rsi, vix-inverse-filter, stochastic-confirm, wma-heikin-average, strategy-long, strategy-short, session-hours, trading-window, multi-filter-entry, ha-trend-exit, ema-smoothed-ha, inverse-security-data, rsi-ma-cross, stoch-k-d, bull-bear-gates, margin-strategy, plotted-ha-candles, inverse-ha-trend


ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => 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)

// CHART rsi
rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="Chart RSI Settings")
rsiSourceInput = input.source(close, "RSI Source", group="Chart RSI Settings")
maTypeInput = input.string("SMA", title="RSI MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Chart RSI Settings")
maLengthInput = input.int(14, title="RSI MA Length", group="Chart RSI Settings")
bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="Chart RSI Settings")

up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)

chartrsi_bull = rsi > rsiMA
chartrsi_bear = rsi < rsiMA
// CHART rsi

// 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


// VIX inverse
symbol = input.symbol('VIX', title = 'Symbol to Use', group = 'VIX Inverse Settings')
symbol_tf = input.timeframe('', title = 'Timeframe to Use', group = 'VIX Inverse Settings')

inverse_open = request.security(symbol, symbol_tf, symbol_tf == '' ? open : open[1], lookahead = barmerge.lookahead_on)
inverse_high = request.security(symbol, symbol_tf, symbol_tf == '' ? high : high[1], lookahead = barmerge.lookahead_on)
inverse_low = request.security(symbol, symbol_tf, symbol_tf == '' ? low : low[1], lookahead = barmerge.lookahead_on)
inverse_close = request.security(symbol, symbol_tf, symbol_tf == '' ? close : close[1], lookahead = barmerge.lookahead_on)

// RSI
inverse_rsiLengthInput = input.int(14, minval=1, title="RSI Length", group = 'VIX Inverse Settings')
inverse_rsiSourceInput = inverse_close
inverse_maTypeInput = input.string("SMA", title="RSI MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group = 'VIX Inverse Settings')
inverse_maLengthInput = input.int(14, title="RSI MA Length", group = 'VIX Inverse Settings')

inverse_up = ta.rma(math.max(ta.change(inverse_rsiSourceInput), 0), inverse_rsiLengthInput)
inverse_down = ta.rma(-math.min(ta.change(inverse_rsiSourceInput), 0), inverse_rsiLengthInput)
inverse_rsi = inverse_down == 0 ? 100 : inverse_up == 0 ? 0 : 100 - (100 / (1 + inverse_up / inverse_down))
inverse_rsiMA = ma(inverse_rsi, inverse_maLengthInput, inverse_maTypeInput)

inversersi_bull = inverse_rsi > inverse_rsiMA
inversersi_bear = inverse_rsi < inverse_rsiMA

// HA
inverse_len = input.int(10, minval=1, maxval=500, title="HA Length", group = 'VIX Inverse Settings')
inverse_haClose = (inverse_open + inverse_high + inverse_low + inverse_close) / 4
inverse_haOpen = float(na)
inverse_haOpen := na(inverse_haOpen[1]) ? (inverse_open + inverse_close) / 2 : (nz(inverse_haOpen[1]) + nz(inverse_haClose[1])) / 2
inverse_haHigh = math.max(inverse_high, math.max(inverse_haOpen, inverse_haClose))
inverse_haLow = math.min(inverse_low, math.min(inverse_haOpen, inverse_haClose))

// STOCH
inverse_periodK = input.int(14, title="Stoch %K Length", minval=1, group = 'VIX Inverse Settings')
inverse_smoothK = input.int(3, title="Stock %K Smoothing", minval=1, group = 'VIX Inverse Settings')
inverse_periodD = input.int(3, title="Stock %D Smoothing", minval=1, group = 'VIX Inverse Settings')
inverse_k = ta.sma(ta.stoch(inverse_close, inverse_high, inverse_low, inverse_periodK), inverse_smoothK)
inverse_d = ta.sma(inverse_k, inverse_periodD)

// // //
inverse_avg = math.avg(inverse_haOpen,inverse_haHigh,inverse_haLow,inverse_haClose)
inverse_HA_movingAverage = ta.wma(inverse_avg, inverse_len)

inverse_bull = inverse_HA_movingAverage <= inverse_HA_movingAverage[1] and inverse_rsi < inverse_rsiMA and inverse_k < inverse_d
inverse_bear = inverse_HA_movingAverage > inverse_HA_movingAverage[1] and inverse_rsi > inverse_rsiMA and inverse_k > inverse_d
// VIX inverse


// --STRATEGY INPUTS-- //
strategy_start = input.time(timestamp("01 January 2020 00:00:00 UTC-5"), "Strategy Start Date", group = "Strategy Settings", 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 = "Strategy Settings", inline = '2')
trading_time = input.session("0930-1600", title = " ", tooltip = "This uses Eastern Time Zone or U.S. NY Market Hours.", group = "Strategy Settings", 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 = "Strategy Settings", inline = '3')
short_trades = input.bool(true, title = "Short Trades", tooltip = "Do we want to take short trades?" , group = "Strategy Settings", inline = '4')

long_entry = long_trades and trading_hours_cond and chartrsi_bull and chartha_bull and inverse_bull
long_exit = long_trades and chartha_bull[1] and not chartha_bull

short_entry = short_trades and trading_hours_cond and chartrsi_bear and chartha_bear and inverse_bear
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 evaluates market conditions against external volatility data from an inverse symbol, generating long and short trade entries when trend, oscillator, and volatility filters align. The script permits trading restricted to specific session hours and reverses positions upon trend change. Key inputs modify smoothing lengths, RSI moving average types, external symbol selection, and session windows. By default, the strategy contains no stop loss or take profit orders.

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, Oscillators & momentum, Volatility & bands, Sessions & time

Markets

Indices, Stocks

Timeframes

Any timeframe

Risk Notes

  • 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
RSI Lengthint14rsiLengthInput
RSI SourcesourceclosersiSourceInput
RSI MA TypestringSMAmaTypeInput
RSI MA Lengthint14maLengthInput
BB StdDevfloat2.0bbMultInput
Length 1int10len
Length 2int10len2
Symbol to UsesymbolVIXsymbol
Timeframe to Usetimeframesymbol_tf
RSI Lengthint14inverse_rsiLengthInput
RSI MA TypestringSMAinverse_maTypeInput
RSI MA Lengthint14inverse_maLengthInput
Show all 21 settings
SettingTypeDefaultVariable
HA Lengthint10inverse_len
Stoch %K Lengthint14inverse_periodK
Stock %K Smoothingint3inverse_smoothK
Stock %D Smoothingint3inverse_periodD
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

106 stars

This strategy enters long positions during a specified trading session when multiple technical indicators align. It executes a buy order when the low drops below the lower Bollinger Band while RSI and ADX exceed configurable threshold values, price closes abov

Strategy v4 Volatility & bandsOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of Bollinger Band + RSI + ADX + MACD

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
13 stars

This strategy overlays the price chart to trade DAX futures during European market hours. It calculates exponential and simple moving averages, RSI, MACD, Bollinger Bands, ATR, and realized volatility to simulate VIX levels. Trades execute when session time fi

Strategy v5 Sessions & timeOscillators & momentum
Updated 8 months ago · Custom licence GitHub repository of ClaudeHedge - DAX Session Strategy

RSI Mean Reversion

by GifariKemal
3 stars

This strategy plots entry signals, stop loss, take profit levels, and an information panel directly on the price chart. It combines a relative strength index mean reversion model with ATR percentile thresholds to filter trades based on volatility conditions. T

Strategy v5 Oscillators & momentumVolatility & bands
Updated 3 days ago · MIT GitHub repository of RSI Mean Reversion
2 stars

Gold Multi-TF NYSE Scalper v2 is an intraday trading strategy for XAUUSD that seeks momentum entries by aligning RSI and EMA bias across multiple timeframes. It filters trades using an optional NYSE session clock and an ATR volatility spike check. Entries exit

Strategy v6 Oscillators & momentumVolatility & bands
Updated 7 days ago · None stated GitHub repository of Gold Multi-TF NYSE Scalper v2

RSI Strategy

by Web3Degenerate
2 stars

This strategy combines RSI extreme condition filters with engulfing candlestick patterns to identify reversal entries. It opens positions on confirmed bars when an overbought or oversold RSI aligns with a bullish or bearish engulfing pattern. Stop losses are c

Strategy v5 Oscillators & momentumCandlestick patterns
Updated 2 years ago · None stated GitHub repository of RSI Strategy

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