Pine Script force_overlay: draw on the price chart from a pane indicator
How force_overlay = true works in Pine Script v5 and v6: which functions take it, a working RSI example that marks signals on the candles, and what stays in the pane.
force_overlay = true lets an indicator that lives in its own pane draw some of its visuals on the main price chart. A script declared with indicator(overlay = false), such as an RSI, can keep its RSI line in the pane and still put buy and sell marks, a background colour or labels on the candles. SuperCharting supports force_overlay for every call that takes it in Pine Script v5 and v6.
Which functions take force_overlay
Takes force_overlay | Does not take it |
|---|---|
plot(), plotshape(), plotchar(), plotarrow() | fill(): it follows its two plots instead |
plotcandle(), plotbar() | hline(): always stays in the script's pane |
bgcolor() | barcolor(): already colours the main chart's bars |
label.new(), line.new(), box.new() | |
polyline.new(), table.new() |
Leave it out, or set it to false, and the visual stays where the script's overlay setting puts it. On a script that already has overlay = true, the argument changes nothing.
A working example: RSI in a pane, signals on the candles
//@version=6
indicator("RSI with signals on price", overlay = false)
len = input.int(14, "RSI length")
r = ta.rsi(close, len)
// In the RSI pane
plot(r, "RSI", color.purple)
hline(70, "Overbought")
hline(30, "Oversold")
// On the price chart
plot(ta.sma(close, 20), "SMA 20", color.orange, force_overlay = true)
plotshape(ta.crossover(r, 30), "RSI up", shape.triangleup, location.belowbar,
color.green, size = size.small, force_overlay = true)
plotshape(ta.crossunder(r, 70), "RSI down", shape.triangledown, location.abovebar,
color.red, size = size.small, force_overlay = true)
bgcolor(r > 70 ? color.new(color.red, 90) : na, force_overlay = true)
The RSI line and the two horizontal lines stay in the pane. The 20-period SMA, the triangles and the red background are drawn on the candles and scaled with the price axis.
How it behaves in SuperCharting
- The legend and data window still list every plot under the indicator's name, including the ones drawn on the price chart. Style settings, the eye toggle and alerts work as before.
- A fill follows its plots. If both plots of a
fill()useforce_overlay = true, the fill moves to the price chart with them. If only one of them moves, the fill stays in the pane. - A linefill follows its lines in the same way when both lines are forced.
- Drawings keep their coordinates. A
label.new()orbox.new()withforce_overlay = trueis placed at the same bar and price on the main chart, so use price levels such ashighorlowfor itsy, not the oscillator's value. hline()cannot be moved. To draw a fixed price level on the candles from a pane script, useplot()with a constant value andforce_overlay = true, or aline.new()withextend.both.
How to try it
- Open a chart, for example
NSE:NIFTYon the 15m interval. - Open the Pine Editor at the bottom of the screen.
- Paste the example above and click Add to chart.
- The RSI appears in a new pane, and the SMA, triangles and background appear on the candles.
If the script does not compile, the editor shows the line and the error. The free Pine Script checker checks a script without an account, and the Pine Script errors hub explains the common messages.
Frequently asked questions
What does force_overlay do in Pine Script?
It draws one plot, shape, background or drawing on the main price chart while the rest of the indicator stays in its own pane.
Which Pine version supports force_overlay?
Pine Script v5 and v6 accept it. SuperCharting supports it in both.
Why is my hline not moving to the chart?
hline() has no force_overlay argument. Use plot() with a constant value and force_overlay = true instead.
Does force_overlay work with alerts?
Yes. Alerts read the script's values, not where they are drawn, so alertcondition() and alert() work the same whether a plot is in the pane or on the price chart.