Trading Made Easy Pressure Oscillator
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © christoefert

//@version=5
indicator(title="Trading Made Easy Pressure Oscillator", shorttitle="TME_PO", format=format.price, precision=2, timeframe="", timeframe_gaps=true)


//Pressure Oscillator Setup
shortlen=input.int(8, "Short Length", minval=1)
longlen=input.int(21, "Long Length", minval=1)
src = input(close, title="Momentum Oscillator Source")
exp = input(false, "exponential")
esma(source, length)=>
	s = ta.sma(source, length)
	e = ta.ema(source, length)
	exp ? e : s
short = esma(src, shortlen)
long = esma(src, longlen)
po = (short - long)

//Histogram Colouring
iff_1 = po > nz(po[1]) ? color.new(color.white, 0) : color.new(color.gray, 0)
iff_2 = po < nz(po[1]) ? color.new(color.orange, 0) : color.new(color.yellow, 0)
momentum_color = po > 0 ? iff_1 : iff_2

//Squeeze Criteria Using Bollinger Bands Width

length = input.int(20, minval=1)
src2 = input(close, title="Source for Pressure")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")
basis = ta.sma(src2, length)
dev = mult * ta.stdev(src2, length)
upper = basis + dev
lower = basis - dev
bbw = (upper-lower)/basis
Trigger = ta.ema(bbw, 21)

//Pressure Conditions
NoSqz = bbw > Trigger
Sqz = bbw < Trigger
sq_color = Sqz ? color.new(color.red, 0) : color.new(color.green, 0)

//Plot Everything
plot(po, color=momentum_color, style=plot.style_columns, title="Momentum Oscillator")
plot(0, title='Pressure', color=sq_color, style=plot.style_circles, linewidth=2)
