Chiko-Span Momentum_PineScript_Version5
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © KobySK

//@version=5
indicator("Chiko-Span Momentum_PineScript_Version5", "CSM_P5", false)

// input
src = input.source(close, "Chiko-span source")
chart = input.source(open, "Chart to compare with Chiko-span")
len = input.int(26, "Chiko-span length")
type = input.string("Rate of Momentum", "Type of Momentum", options=["Divergence of Momentum", "Rate of Momentum"])
loc = input.int(-26, "Location of Momentum")

// momentum
mom = switch type
    "Rate of Momentum" => src / chart[len-1] * 100
    "Divergence of Momentum" => src - chart[len-1]

// plot
plot(mom, "Chiko-Span Momemtum", color.lime, 2, style=plot.style_line, offset=loc<0 ? loc+1 : loc>0 ? loc-1 : 0)

// h-line
level = type == "Rate of Momentum" ? 100 : 0
hline(level)