Skip to main content

Session & Volatility Tools

Session candles, ATR trailing stop tool, day trading tools, displaying stops and targets on the chart, and building session-aware indicators.

From Thrive on YouTube

Watch the matching Thrive video

Watch the series
Trading Indicators, Honestly: What They Can and Cannot Do

Trading Indicators, Honestly: What They Can and Cannot Do

Part of Trading Journal and Performance Review. Education only. Not financial advice.

Session Candles Indicator

Session candles draw the open, high, low, and close of entire trading sessions (Asia, London, New York) as overlay candles on your intraday chart. This reveals which session is driving price and where key levels formed. On a 15-minute BTC chart, you can see the Asian session range as a single candle, then watch whether London breaks out of that range or reverses. This is foundational for session-based trading strategies.

pine-Session candles with range drawing
1//@version=5
2indicator("Session Candles", overlay=true,
3 max_boxes_count=500)
4
5showAsia = input.bool(true, "Show Asia")
6showLondon = input.bool(true, "Show London")
7showNY = input.bool(true, "Show New York")
8
9asiaTime = "2000-0400"
10londonTime = "0300-1130"
11nyTime = "0930-1600"
12tz = "America/New_York"
13
14drawSession(sessionStr, boxColor, bgColor) =>
15 inSession = not na(time("", sessionStr, tz))
16 newSession = inSession and not inSession[1]
17
18 var float sessOpen = na
19 var float sessHigh = na
20 var float sessLow = na
21 var int sessBar = na
22
23 if newSession
24 sessOpen := open
25 sessHigh := high
26 sessLow := low
27 sessBar := bar_index
28 else if inSession
29 sessHigh := math.max(sessHigh, high)
30 sessLow := math.min(sessLow, low)
31
32 endSession = not inSession and inSession[1]
33 if endSession and not na(sessBar)
34 box.new(sessBar, sessHigh, bar_index[1], sessLow,
35 border_color=boxColor, bgcolor=bgColor,
36 border_width=1)
37
38if showAsia
39 drawSession(asiaTime, color.new(color.purple, 30),
40 color.new(color.purple, 92))
41if showLondon
42 drawSession(londonTime, color.new(color.blue, 30),
43 color.new(color.blue, 92))
44if showNY
45 drawSession(nyTime, color.new(color.orange, 30),
46 color.new(color.orange, 92))
1

Session detection

The time() function with a session string returns a non-na value only when the current bar falls within the specified time window. The transition from na to non-na marks the session open. Using a timezone parameter ensures consistency regardless of the chart's local timezone.
2

Tracking session OHLC

Variables declared with var persist across bars. At session open, we reset the open/high/low. During the session, we continuously update the high and low. At session close (when the bar exits the time window), we have the complete OHLC range to draw.
3

Drawing the box

box.new() draws a rectangle from the session start bar to the session end bar, bounded by the session high and low. The background is highly transparent (92) to avoid obscuring candles, while the border provides a clear visual boundary.

ATR Trailing Stop Tool

An ATR trailing stop dynamically adjusts your stop loss based on current volatility. In trending markets, the stop follows price at a distance of N times ATR. When volatility expands (like during a BTC liquidation cascade), the stop widens to avoid getting stopped out on noise. When volatility contracts, the stop tightens to lock in profits. This is superior to fixed percentage stops because it adapts to market conditions automatically.

pine-ATR trailing stop indicator
1//@version=5
2indicator("ATR Trailing Stop", overlay=true)
3
4atrLen = input.int(14, "ATR Length")
5atrMult = input.float(2.5, "ATR Multiplier", step=0.1)
6src = input.source(close, "Source")
7
8atr = ta.atr(atrLen)
9
10var float trail = na
11var int dir = 1
12
13longStop = src - atr * atrMult
14shortStop = src + atr * atrMult
15
16// Trail logic: ratchet the stop in the trend direction
17if na(trail[1])
18 trail := longStop
19 dir := 1
20else
21 if dir == 1
22 trail := math.max(nz(trail[1]), longStop)
23 if src < trail
24 trail := shortStop
25 dir := -1
26 else
27 trail := math.min(nz(trail[1]), shortStop)
28 if src > trail
29 trail := longStop
30 dir := 1
31
32// Visualization
33trailColor = dir == 1 ? color.new(color.green, 0) :
34 color.new(color.red, 0)
35plot(trail, "ATR Trail", trailColor, 2, plot.style_linebr)
36
37// Flip signals
38buyFlip = dir == 1 and dir[1] == -1
39sellFlip = dir == -1 and dir[1] == 1
40plotshape(buyFlip, "Buy Flip", shape.triangleup,
41 location.belowbar, color.green, size=size.small)
42plotshape(sellFlip, "Sell Flip", shape.triangledown,
43 location.abovebar, color.red, size=size.small)
44
45bgcolor(dir == 1 ? color.new(color.green, 95) :
46 color.new(color.red, 95))

Multiplier selection

The ATR multiplier is the most important parameter. Too tight (below 1.5) and you get chopped out of good trends by normal volatility. Too wide (above 4.0) and you give back too much profit before the stop triggers. For BTC on the 4H timeframe, 2.0–3.0 is the sweet spot. For SOL, which has higher relative volatility, 2.5–3.5 tends to work better. Always test on your specific asset and timeframe.

Day Trading Tool: Session Levels and Pivots

A session-aware day trading tool combines the previous session's high, low, and close with classic pivot point calculations to produce key intraday levels. Pivot points have been used by floor traders for decades. They represent equilibrium prices around which the market tends to rotate. For crypto, the previous day's high and low are the most respected intraday levels because they represent the boundaries of the last full cycle of trading.

pine-Session-aware day trading levels
1//@version=5
2indicator("Day Trading Levels", overlay=true,
3 max_lines_count=500, max_labels_count=500)
4
5showPivots = input.bool(true, "Show Pivot Points")
6showPDHL = input.bool(true, "Show Prev Day H/L")
7
8// Previous day OHLC (non-repainting)
9pdHigh = request.security(syminfo.tickerid, "D",
10 high[1], lookahead=barmerge.lookahead_on)
11pdLow = request.security(syminfo.tickerid, "D",
12 low[1], lookahead=barmerge.lookahead_on)
13pdClose = request.security(syminfo.tickerid, "D",
14 close[1], lookahead=barmerge.lookahead_on)
15
16// Classic pivot points
17pp = (pdHigh + pdLow + pdClose) / 3
18r1 = 2 * pp - pdLow
19s1 = 2 * pp - pdHigh
20r2 = pp + (pdHigh - pdLow)
21s2 = pp - (pdHigh - pdLow)
22
23if showPDHL
24 plot(pdHigh, "Prev Day High", color.new(color.red, 30), 1,
25 plot.style_stepline)
26 plot(pdLow, "Prev Day Low", color.new(color.green, 30), 1,
27 plot.style_stepline)
28if showPivots
29 plot(pp, "Pivot", color.new(color.yellow, 20), 2,
30 plot.style_stepline)
31 plot(r1, "R1", color.new(color.red, 50), 1,
32 plot.style_stepline)
33 plot(r2, "R2", color.new(color.red, 30), 1,
34 plot.style_stepline)
35 plot(s1, "S1", color.new(color.green, 50), 1,
36 plot.style_stepline)
37 plot(s2, "S2", color.new(color.green, 30), 1,
38 plot.style_stepline)
Pivot Point (PP)(High + Low + Close) / 3. Central equilibrium level. Price above PP = bullish bias, below = bearish bias.
R1 / S1First resistance and support levels. Most common intraday reversal zones. ~70% of price action stays within R1-S1.
R2 / S2Second resistance and support levels. Reached on high-volatility days. Breakout targets when R1/S1 fail to hold.
Prev Day HighThe highest price from the prior 24h session. A breakout above this level signals continuation and fresh buying.
Prev Day LowThe lowest price from the prior 24h session. A breakdown below signals continuation selling and potential capitulation.

Displaying Stops and Targets on Chart

Visualizing your stop loss, take profit, and risk-reward ratio directly on the chart eliminates guesswork. This tool draws horizontal lines at your entry, stop, and target levels, then adds a label showing the exact R:R ratio. Professional traders plan every trade visually before entering. This tool makes that process part of your indicator setup.

pine-Stops and targets with R:R labels
1//@version=5
2indicator("Trade Planner", overlay=true,
3 max_lines_count=50, max_labels_count=50)
4
5atrLen = input.int(14, "ATR Length")
6slMult = input.float(2.0, "Stop ATR Mult", step=0.1)
7tpMult = input.float(3.0, "Target ATR Mult", step=0.1)
8
9ema21 = ta.ema(close, 21)
10atr = ta.atr(atrLen)
11
12bullEntry = ta.crossover(close, ema21) and barstate.isconfirmed
13
14if bullEntry
15 entryPrice = close
16 stopPrice = entryPrice - atr * slMult
17 tpPrice = entryPrice + atr * tpMult
18 rr = tpMult / slMult
19
20 line.new(bar_index, entryPrice, bar_index + 20, entryPrice,
21 color=color.white, width=2, style=line.style_solid)
22 line.new(bar_index, stopPrice, bar_index + 20, stopPrice,
23 color=color.red, width=1, style=line.style_dashed)
24 line.new(bar_index, tpPrice, bar_index + 20, tpPrice,
25 color=color.green, width=1, style=line.style_dashed)
26
27 label.new(bar_index + 22, tpPrice,
28 "TP: " + str.tostring(tpPrice, "#.##"),
29 color=color.new(color.green, 70),
30 textcolor=color.green, style=label.style_label_left,
31 size=size.tiny)
32 label.new(bar_index + 22, stopPrice,
33 "SL: " + str.tostring(stopPrice, "#.##"),
34 color=color.new(color.red, 70),
35 textcolor=color.red, style=label.style_label_left,
36 size=size.tiny)
37 label.new(bar_index + 22, entryPrice,
38 "R:R " + str.tostring(rr, "#.#") + ":1",
39 color=color.new(color.white, 70),
40 textcolor=color.white, style=label.style_label_left,
41 size=size.tiny)

Always define your exit before entry

Before you enter any trade, you should know exactly where your stop loss and take profit levels are. This tool forces that discipline. It only draws levels on confirmed entry signals, showing you the full trade plan before you execute. On BTC, a minimum R:R of 1.5:1 is recommended. On higher-volatility assets like SOL, aim for 2:1 or higher to account for wider stop requirements.

Complete Session-Aware Trading Tool

This comprehensive indicator combines session detection, ATR trailing stops, pivot levels, and entry/exit visualization into a single tool. It identifies the current trading session, shows the trailing stop appropriate for current volatility, plots key intraday levels, and marks entry signals when a session breakout occurs with confirming momentum. This is the type of multi-component tool that professional day traders build for their specific workflow.

pine-Session-aware complete trading tool
1//@version=5
2indicator("Session Trading Tool", overlay=true,
3 max_lines_count=100, max_labels_count=100)
4
5atrLen = input.int(14, "ATR Length")
6atrMult = input.float(2.0, "ATR Multiplier", step=0.1)
7
8tz = "America/New_York"
9inAsia = not na(time("", "2000-0400", tz))
10inLondon = not na(time("", "0300-1130", tz))
11inNY = not na(time("", "0930-1600", tz))
12
13sessName = inNY ? "NY" : inLondon ? "LON" : inAsia ? "ASIA" : "OFF"
14
15// Previous day levels (non-repainting)
16pdH = request.security(syminfo.tickerid, "D",
17 high[1], lookahead=barmerge.lookahead_on)
18pdL = request.security(syminfo.tickerid, "D",
19 low[1], lookahead=barmerge.lookahead_on)
20pp = (pdH + pdL + request.security(syminfo.tickerid, "D",
21 close[1], lookahead=barmerge.lookahead_on)) / 3
22
23// ATR trailing stop
24atr = ta.atr(atrLen)
25var float trail = na
26var int dir = 1
27longStop = close - atr * atrMult
28shortStop = close + atr * atrMult
29
30if na(trail[1])
31 trail := longStop
32 dir := 1
33else if dir == 1
34 trail := math.max(nz(trail[1]), longStop)
35 if close < trail
36 trail := shortStop
37 dir := -1
38else
39 trail := math.min(nz(trail[1]), shortStop)
40 if close > trail
41 trail := longStop
42 dir := 1
43
44plot(trail, "ATR Trail", dir == 1 ? color.green : color.red,
45 2, plot.style_linebr)
46plot(pp, "Pivot", color.new(color.yellow, 30), 1,
47 plot.style_stepline)
48plot(pdH, "Prev High", color.new(color.red, 50), 1,
49 plot.style_stepline)
50plot(pdL, "Prev Low", color.new(color.green, 50), 1,
51 plot.style_stepline)
52
53// Session background
54bgCol = inNY ? color.new(color.orange, 95) :
55 inLondon ? color.new(color.blue, 95) :
56 inAsia ? color.new(color.purple, 95) : na
57bgcolor(bgCol)
58
59if barstate.islast
60 label.new(bar_index + 3, close, sessName,
61 color=color.new(color.gray, 60),
62 textcolor=color.white, size=size.small,
63 style=label.style_label_left)
Session identification

Automatically detects Asia, London, and New York sessions with colored backgrounds

ATR trailing stop

Dynamic stop that adapts to current volatility: widens in chaos, tightens in calm

Previous day levels

Non-repainting high, low, and pivot point from the prior session

Session label

Current session name displayed at the right edge of the chart

Combined workflow

One indicator replaces 3–4 separate tools, keeping your chart clean

Put this lesson to work

Free on Thrive, no account needed.