Momentum 2.0 [AstrideUnicorn]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AstrideUnicorn

//@version=5
indicator("Momentum 2.0", overlay = false)

source = close

// Script Inputs 
window = input(defval=15, title="Oscillator Period")
base_level_window = input.int(defval=700, title="Base Level Period", minval=300)

// Calculate normalized and smoothed momentum oscillator
momentum = ta.mom(source, window) 
momentum_normalized = ( momentum ) / ta.stdev(momentum, base_level_window)
momentum_smoothed = ta.linreg(momentum_normalized, 30,0)

// Calculated the base-level
momentum_base = -ta.ema(momentum_normalized,base_level_window)

// Plot the oscillator and base-level
plot(momentum_smoothed, color = momentum_smoothed > momentum_base? color.green: momentum_smoothed < momentum_base? color.red: color.blue, style = plot.style_columns)
plot(momentum_base, color=color.blue, linewidth=2)

// Calculate base-level cross signals
bullish = ta.crossover(momentum_smoothed, momentum_base) and barstate.isconfirmed
bearish = ta.crossunder(momentum_smoothed, momentum_base) and barstate.isconfirmed

if bullish
    alert("Momentum 2.0 BUY signal")
    
if bearish
    alert("Momentum 2.0 SELL signal")    

// Plot trading signals labels
plotshape(bearish?momentum_base:na,  style=shape.labeldown, color = #9A2A2A, text="▼",textcolor = color.white, size=size.normal, location = location.absolute)
plotshape(bullish?momentum_base:na, style=shape.labelup, color = #006400, text="▲", textcolor = color.white, size=size.normal, location = location.absolute)
