Strategy · Pine Script v5 · On the chart

Session Wicks

by g-moe· code credited to goodgains

This strategy executes long and short trades on the price chart by combining multi-timeframe smoothed Heikin-Ashi trends, higher-timeframe Hull Moving Average variations, and an ATR-based trailing stop.

View on GitHub

Repaints

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

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

session-wicks.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("Session Wicks", overlay=true, margin_long=100, margin_short=100)

// @keywords: session-wicks, heikin-ashi, hull-moving-average, atr-trailing-stop, mtf-trend, long-short-strategy, supertrend-style, session-hours, take-profit, stop-loss, trend-alignment, bar-highlight, ha-timeframe, hull-variation, crossover-entry, strategy-orders, multi-filter, trend-background, entry-exit, position-lines

// MTF HA
ha_tf   = input.timeframe('30', title = 'HA Timeframe', group = 'HA Settings', inline = '0')
len     = input(10, title="Length 1", group = 'HA Settings', inline = '1')
len2    = input(10, title="Length 2", group = 'HA Settings', inline = '2')


f_mtf_ha() =>
    o=ta.ema(open,len)
    c=ta.ema(close,len)
    h=ta.ema(high,len)
    l=ta.ema(low,len)

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

    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.lime

    trend = o2 > c2 ? -1 : 1

    trend[1]

ha_trend = request.security(syminfo.ticker, ha_tf, f_mtf_ha(), lookahead = barmerge.lookahead_on)





// MTF HULL
hull_src = input(close, title='Source', group = 'Hull Settings', inline = '0')
modeSwitch = input.string('Hma', title='Hull Variation', options=['Hma', 'Thma', 'Ehma'], group = 'Hull Settings', inline = '1')
hull_length = input(55, title='Length(180-200 for floating S/R , 55 for swing entry)', group = 'Hull Settings', inline = '2')
hull_tf = input.timeframe('15', title='Higher timeframe', group = 'Hull Settings', inline = '4')

f_mtf_hull() =>
    float ma_value = switch modeSwitch
        "Hma" => ta.wma(2 * ta.wma(hull_src, hull_length / 2) - ta.wma(hull_src, hull_length), math.round(math.sqrt(hull_length)))
        "Ehma" => ta.ema(2 * ta.ema(hull_src, hull_length / 2) - ta.ema(hull_src, hull_length), math.round(math.sqrt(hull_length)))
        "THMA" => ta.wma(ta.wma(hull_src, hull_length / 3) * 3 - ta.wma(hull_src, hull_length / 2) - ta.wma(hull_src, hull_length), hull_length)
        => ta.wma(2 * ta.wma(hull_src, hull_length / 2) - ta.wma(hull_src, hull_length), math.round(math.sqrt(hull_length)))

    hull_color = ma_value > ma_value[2] ? 1 : -1

    hull_color[1]


hull_trend = request.security(syminfo.ticker, hull_tf, f_mtf_hull(), lookahead = barmerge.lookahead_on)




// chart signals
src = close

keyvalue = input.float(3, title='Key Vaule. \'This changes the sensitivity\'', step=.5, group = 'ST Settings', inline = '1')
atrperiod = input(10, title='ATR Period')
xATR = ta.atr(atrperiod)
nLoss = keyvalue * xATR

xATRTrailingStop = 0.0
iff_1 = src > nz(xATRTrailingStop[1], 0) ? src - nLoss : src + nLoss
iff_2 = src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), src + nLoss) : iff_1
xATRTrailingStop := src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), src - nLoss) : iff_2

pos = 0
iff_3 = src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0) ? -1 : nz(pos[1], 0)
pos := src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0) ? 1 : iff_3

xcolor = pos == -1 ? color.red : pos == 1 ? color.green : color.blue
signal_buy = ta.crossover(src, xATRTrailingStop)
signal_sell = ta.crossunder(src, xATRTrailingStop)
barcolor = src > xATRTrailingStop ? color.green : color.red
barcolor(barcolor)



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

use_tp      = input.bool(true, title = 'TP', group = "StrategySettings", inline = '5')
tp_amount   = input.float(5.00, title = '', group = "StrategySettings", inline = '5')
use_sl      = input.bool(true, title = 'SL', group = "StrategySettings", inline = '6')
sl_amount   = input.float(5.00, title = '', group = "StrategySettings", inline = '6')

var int trend = 0
var bool buy_signal = false
var bool sell_signal = false

trend := hull_trend == 1 and ha_trend == 1 ? 1 : hull_trend == -1 and ha_trend == -1 ? -1 : 0
bgcolor(trend == 1 ? color.new(color.green, 80) : trend == -1 ? color.new(color.red, 80) : na)
buy_signal := trend == 1 and signal_buy
sell_signal := trend == -1 and signal_sell

long_entry = long_trades and trading_hours_cond and buy_signal
long_exit = (not short_trades and sell_signal)

short_entry = short_trades and trading_hours_cond and sell_signal
short_exit = (not long_trades and buy_signal)

var float tp = na
var float sl = na

tp := not use_tp ? na
 : strategy.position_size > 0 ? strategy.position_avg_price + tp_amount 
 : strategy.position_size < 0 ? strategy.position_avg_price - tp_amount 
 : na

sl := not use_sl ? na
 : strategy.position_size > 0 ? strategy.position_avg_price - sl_amount 
 : strategy.position_size < 0 ? strategy.position_avg_price + sl_amount 
 : na

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)

    if not trading_hours_cond
        strategy.close_all('TX', immediately = true)

    if strategy.position_size > 0
        strategy.exit('L_TPSL', 'LE', limit = tp, stop = sl, comment_profit = 'L_TP', comment_loss = 'L_SL')

    if strategy.position_size < 0
        strategy.exit('SS_TPSL', 'SS_E', limit = tp, stop = sl, comment_profit = 'SS_TP', comment_loss = 'SS_SL')
// --ORDERS-- //


plot(strategy.position_avg_price, title = 'Entry', color = color.blue, style = plot.style_circles)
plot(tp, title = 'TP', color = color.green, style = plot.style_circles)
plot(sl, title = 'SL', color = color.red, style = plot.style_circles)

Overview

Users can adjust timeframes, smoothing lengths, Hull formulas, ATR sensitivity multipliers, optional trading session hours, and fixed take-profit and stop-loss targets. The strategy manages exits through enabled stop-loss and take-profit parameters. A notable limitation is that it requests higher-timeframe data with lookahead enabled, which introduces lookahead bias during historical backtesting.

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

Trend, Moving averages, Volatility & bands, Sessions & time

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • Reads higher-timeframe data with lookahead on, so the history can show signals that were not there in real time

Settings

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

SettingTypeDefaultVariable
HA Timeframetimeframe30ha_tf
Length 1int10len
Length 2int10len2
Sourcesourceclosehull_src
Hull VariationstringHmamodeSwitch
Length(180-200 for floating S/R , 55 for swing entry)int55hull_length
Higher timeframetimeframe15hull_tf
Key Vaule. 'This changes the sensitivity'float3keyvalue
ATR Periodint10atrperiod
Strategy Start Datetimetimestamp("01 January 2020 00:00:00 UTC-5")strategy_start
Use Trading Hoursboolfalseuse_trading_hours
session0930-1600trading_time
Show all 18 settings
SettingTypeDefaultVariable
Long Tradesbooltruelong_trades
Short Tradesbooltrueshort_trades
TPbooltrueuse_tp
tp_amountfloat5.00tp_amount
SLbooltrueuse_sl
sl_amountfloat5.00sl_amount
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

4 stars

This strategy trades directional momentum breakouts for crude oil on the price chart. It enters long or short positions when a fast exponential moving average crosses a slow exponential moving average, provided that current Average True Range exceeds its movin

Strategy v6 TrendMoving averages
Updated 2 months ago · MIT GitHub repository of CL Crude Oil Momentum [trugurpala]

3Commas Bot

by regalouisei
2 stars

This strategy draws two moving averages on the price chart and uses their bias to open long or short trades. It places the stop beyond a swing high or low using an ATR risk multiple, then sets a limit exit from the reward-to-risk ratio. An optional ATR trail c

Strategy v5 TrendMoving averages
Updated 8 months ago · None stated GitHub repository of 3Commas Bot
1 stars

The IBKR Safe Forex Strategy is a Pine Script v6 strategy that trades forex pairs using crossovers of 10-period and 50-period EMAs, filtered by a 200-period EMA and restricted to London or New York session overlap. It enters long positions on fast EMA above sl

Strategy v6 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of IBKR Safe Forex Strategy
1 stars

This Pine Script v6 strategy uses multi-timeframe analysis to identify intraday trends and generate trading signals. It requests higher-timeframe data for trend context via EMAs and Supertrend direction. On the local timeframe it plots EMA cross signals for lo

Strategy v6 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Tn Sovereign MTF Intraday v6

Strategy Template

by MoDarK-MK
1 stars

This strategy template provides a modular foundation for building TradingView v6 backtests. It uses a placeholder Exponential Moving Average crossover signal combined with customizable filters for higher-timeframe trend alignment, volatility regime thresholds,

Strategy v6 TrendMoving averages
Updated 7 weeks ago · MPL-2.0 GitHub repository of Strategy Template

This mean-reversion strategy plots Bollinger Bands and a long-term moving average directly on the price chart. It enters trades when price candles penetrate the outer Bollinger Bands beyond a user-defined body percentage, anticipating a price reversal. Entries

Strategy v5 Mean reversionVolatility & bands
Updated 2 months ago · None stated GitHub repository of Bollinger Bands Winner PRO [Alorse]

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