// TMO ((T)rue (M)omentum (O)scilator)
//Mobius V01.05.2018
//#hint: TMO calculates momentum using the delta of price. Giving a much better picture of trend, tend reversals and divergence than momentum oscillators using price.
//@version=6
indicator("TMO (True Momentum Oscillator)", shorttitle="TMO", overlay=false)
// Inputs
length = input.int(14, title="Length")
calcLength = input.int(5, title="Calculation Length")
smoothLength = input.int(3, title="Smooth Length")
// Calculate the TMO value using the same logic as the ThinkScript version
data = 0.0
for i = 0 to length
priceChange = close > open[i] ? 1 : close < open[i] ? -1 : 0
data := data + priceChange
// EMA calculations
ema5 = ta.ema(data, calcLength)
main_val = ta.ema(ema5, smoothLength)
signal_val = ta.ema(main_val, smoothLength)
// Color logic for the lines
mainColor = main_val > signal_val ? color.green : color.red
signalColor = main_val > signal_val ? color.green : color.red
// Plot the main and signal lines and assign their plot handles
p_main = plot(main_val, title="Main", color=mainColor, linewidth=2)
p_signal = plot(signal_val, title="Signal", color=signalColor, linewidth=1)
// Add cloud between main and signal using the plot handles
fill(p_main, p_signal, color = main_val > signal_val ? color.new(color.green, 80) : color.new(color.red, 80))
// Plot horizontal reference line
p_zero = plot(0, title="Zero Line", color=color.gray, linewidth=1, style=plot.style_line)
// Overbought and oversold levels
ob = math.round(length * 0.7)
os = -math.round(length * 0.7)
// Plot the overbought/oversold levels (handles used for the cloud fill later)
p_ob = plot(ob, title="Overbought", color=color.gray, linewidth=1, style=plot.style_line)
p_os = plot(os, title="Oversold", color=color.gray, linewidth=1, style=plot.style_line)
// Additional lines for the cloud area
obLine_val = length
osLine_val = -length
p_obLine = plot(obLine_val, title="Overbought Line", color=color.gray, linewidth=1, style=plot.style_line)
p_osLine = plot(osLine_val, title="Oversold Line", color=color.gray, linewidth=1, style=plot.style_line)
// Add overbought and oversold clouds using the plot handles
fill(p_ob, p_obLine, color=color.new(color.red, 90))
fill(p_osLine, p_os, color=color.new(color.green, 90))
