LBR Paintbars [LazyBear]

Added coloring of LB             bars above/below Keltner Channel (as suggested by user @20813 below in the comments).

Updated code:

See comments section below for a sample chart. Copy the code from the pastebin above and update your local             copy (TV doesn't allow me to update an already published code -- yet!).

Added features:
- Switch ON/OFF KC
- Mark LB             bars above/below KC


The LBR PaintBars indicator changes the colour of the price bars based on the trend direction (derived from price & volatility bands). This is mostly used as a confirmation indicator.

For the Pine coders: I suggest trying stdev() in lieu of atr()...some wild combinations can be derived from this simple idea :)

Indicator supports the following options:
- Switching on/off volatility bands
- Switching on/off LBR colors (lime/maroon).
- Color non-LBR bars (blue).

Thanks @mseaworthy for pinging me with this idea.

Complete list of my indicators:
Remove from Favorite Scripts Add to Favorite Scripts
// @author LazyBear 
// List of all my indicators: 
study("LBR PaintBars [LazyBear]", overlay=true, shorttitle="LBRBARS_LB")
lbperiod = input (16, title="HL Length")
atrperiod = input(9, title="ATR Length")
mult = input (2.5, minval=0, title="ATR Multiplier")
bcf = input(true, title="Color LBR Bars?")
mnlb=input(false, title="Color non LBR Bars?" )
svb=input(false, title="Show Volatility Bands?")
aatr = mult * sma(atr(atrperiod), atrperiod) 
b1 = lowest(low, lbperiod) + aatr 
b2 = highest(high, lbperiod) - aatr 
uvf =  (close > b1 and close > b2)
lvf = (close < b1 and close < b2 )
uv = plot(svb?b2:na, style=line, linewidth=3, color=red, title="UpperBand")
lv = plot(svb?b1:na, style=line, linewidth=3, color=green, title="LowBand")
bc = (bcf ? uvf ? lime : lvf ? maroon : mnlb?blue:na : (not (uvf or lvf) and mnlb ? blue : na ) )
"Wild Ideas"??? Questions: 1. Please explain advantage of using st dev vs. ATR in terms of effective use of the indicator. 2. If there is an advantage, could you please show what the code would be & where it would go (I'd be glad to do it myself). Also, is there more info about this indicator? Thanks
LazyBear PRO rmwaddelljr
To rephrase your question 1, you are wondering about "advantage of Bollinger bands over Keltner channel" (BB uses stdev, KC uses atr). There is no clear favorite for me (though I end up using BB most of the time, just because I am relatively more familiar with it than KC).

Here are some links I found on Google for LBRPaintbar:

rmwaddelljr LazyBear
Thanks. I did google before I posted this morning. Interesting. So how would you modify the code to reflect either (ATR or StDev)?
LazyBear PRO rmwaddelljr
It uses ATR now. To use stdev(), change atr(atrperiod) to stdev(close, atrperiod). Also change atrperiod to 20 (to reflect standard BB).

If you use the new code (, you might want to change the calc_kc to calc_stdev and use that for all calculations/renderings.
rmwaddelljr LazyBear
How do I fix "line 8:8 no viable alternative at input"
LazyBear PRO rmwaddelljr
Can you show me that code?
rmwaddelljr LazyBear
atrperiod, close = input (9, title= "ATR Length")
LazyBear PRO rmwaddelljr
"atrperiod, close=" has syntax error.

It shd read "atrperiod=input(...)"
rmwaddelljr LazyBear
Sorry, now confused. You said earlier today to use: It uses ATR now. To use stdev(), change atr(atrperiod) to stdev(close, atrperiod). Also change atrperiod to 20 (to reflect standard BB)... Where am I going wrong?
LazyBear PRO rmwaddelljr
you didnt specify "stdev" :)

If you want stdev, that line is not what you shd change. Line 13 shd be updated to:

aatr = mult * sma(stdev(close, atrperiod), atrperiod)

And then u can change atrperiod (via options page) to 20 and see how things look.

Remember, in the above line, a multiplier of 1 is assumed. If you want to change the 2nd deviation, you shd do 2*stdev()
United States
United Kingdom
Home Stock Screener Forex Signal Finder Cryptocurrency Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators Website & Broker Solutions Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Profile Profile Settings Account and Billing Priority Support Ideas Published Followers Following Private Messages Chat Sign Out