Conditional Plotting in Pine Script: Show or Hide Chart Data
Conditional plotting controls which values or colors a Pine indicator displays. It changes the visualization, not the underlying market data, and does not by itself change strategy orders or alert conditions.
The three examples below demonstrate sparse values, a date filter and moving-average colors. They passed Pineify's syntax checker during this review; that check is not a visual rendering test or a trading-performance test.
Keep the plot call in global scope
TradingView's plot documentation requires plot calls in global scope. Select the value or color with a condition instead of putting the plot call inside a local conditional block.
Returning na for the plotted value leaves no value on that bar. The default line style can bridge missing values; plot.style_linebr avoids connecting across gaps. Hiding with a missing or transparent color is a different choice: the underlying numeric series can still exist.
Example 1: select every third bar
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//@version=6
indicator("Every third bar", "", true)
bool shouldPlot = bar_index % 3 == 0
plot(shouldPlot ? high : na, color = color.fuchsia, linewidth = 6, style = plot.style_linebr)
The modulo condition is true for bar indices 0, 3, 6 and so on in the loaded dataset. The code supplies the high only at those indices. Because the retained values are isolated, inspect the Data Window as well as the chart when checking them; a broken-line style is not the same display as dedicated point markers.
This selection is based on the dataset's bar index, not a permanent calendar schedule. Changing the loaded history can change which timestamps fall on an index divisible by three. Use it to learn conditional selection, not to define "every third trading day" without further rules.
Example 2: show values after a date
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//@version=6
indicator("Plot after date", "", true)
startDate = input.time(timestamp("2025-03-01"))
plot(time > startDate ? close : na)
Here the comparison uses the bar's opening timestamp, time, and is strictly greater than the input. A bar opening exactly at the threshold is excluded. The initial input is March 1, 2025; change it in Settings to inspect another boundary.
TradingView's time documentation distinguishes opening time, closing time and displayed chart timezone. Check the timestamp and timezone interpretation when matching a calendar cutoff, especially for overnight sessions or bars that span the chosen boundary.
This example only hides earlier plotted closes. It does not remove those bars from the dataset, reset an indicator's history or exclude strategy trades. To restrict a backtest, separately constrain the order logic and decide what happens to existing positions at the boundary. Selecting a visually attractive start date after examining outcomes also introduces selection bias.
Example 3: color a moving average
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//@version=6
indicator("Colored moving average", "", true)
int length = input.int(20, "Length", minval = 2)
color bullColor = input.color(color.green, "Bullish")
color bearColor = input.color(color.maroon, "Bearish")
float ma = ta.sma(close, length)
bool isRising = ta.rising(ma, 1)
color maColor = isRising ? bullColor : bearColor
plot(ma, "MA", maColor, 2)
The average is calculated on every bar. With a one-bar comparison, ta.rising(ma, 1) selects green when the average rises; the alternative color includes flat values as well as declines. Green does not measure trend acceleration or guarantee a continuing rise. Maroon does not necessarily mean a decline because equality also takes that branch.
The SMA needs sufficient observations, so an initially missing value is expected. On an open bar, changes to the current close can change both the average and its color. TradingView's execution model explains these realtime recalculations.
Add conditions without changing their meaning
A volume-above-average filter shows bars that meet that numerical comparison. It does not identify "high conviction" or institutional activity. Decide how missing volume should be handled rather than assuming every instrument provides comparable volume data.
A higher-timeframe filter requires a separate choice about completed versus developing values. A hidden plot does not fix repainting in the series feeding it. Consult TradingView's timeframe-request documentation before treating a higher-timeframe condition as final.
Similarly, coloring a detected candle pattern does not verify its predictive value. Test that the displayed condition matches the defined pattern first; evaluate any entry rule separately.
Check the display before measuring a strategy
- Pick bars where the condition is true, false and at an equality boundary.
- Compare the numeric values in the Data Window with the expected inputs.
- Inspect gaps and adjacent transitions at more than one zoom level.
- Observe a live bar and compare again after it closes and after reload.
- Check that alert and order conditions match your intended rule independently of the display.
If performance is a concern, use the Pine Profiler on representative data. A complicated-looking expression is not enough to prove that it is the bottleneck, and hiding a plot does not establish that expensive upstream calculations stop running.
Working with Pineify
Pineify can help author a script and configure supported visual components. Inspect the generated source for the exact plotting behavior you need; do not assume every dynamic plot style can be expressed by every visual control.
Compile the exported script and perform the display checks above. Product access and credit allowances depend on the current offer; no development-time reduction or lifetime entitlement is established by these examples.
Frequently asked questions
Does hiding a plot stop a strategy from trading?
No. Plotting and order conditions are separate. A date filter applied only to a plot does not restrict strategy orders.
Why does a line cross bars where the value is missing?
The default line style can bridge missing values. A broken-line style changes that connection behavior; inspect isolated points separately.
Does maroon always mean the example's average is falling?
No. The non-rising branch also includes an unchanged value. The color reports the condition, not a complete market-state classification.
Does a successful syntax check prove the chart looks correct?
No. Compile checks and visual checks answer different questions. Inspect the chart and Data Window for the intended values, gaps and transitions.


