Velocity
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HGabriel_marius

//@version=5
indicator("Velocity Change",timeframe = '', format = format.percent)

len = input(3, "Initial Point")

src = input(close)

INI = src[len]

CH = ((close - INI)/INI)*100

OP = input(100, "Length of Upper and Lower")
V = (CH / len)

S = (V - V[len])/len

x = ta.stdev(V, OP)
y = ta.stdev(V, OP) * -1

plot(CH, "Change", color = color.red, display = display.status_line)
plot(V, "Speed", color = color.orange)
//plot(S, "Velocity", color = color.blue)

ZE = plot(0,color = color.rgb(151, 151, 151))
PO = plot(x,color = color.white)
NE = plot(y,color = color.white)

fill(ZE, PO, color = color.rgb(76, 175, 79, 90))
fill(ZE, NE, color = color.rgb(255, 82, 82, 90))


ma(source, length, type) =>
    switch type
        "SMA" => ta.sma(source, length)
        "Bollinger Bands" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")

col1 = color.green
col2 = color.red
col3 = color.blue
col4 = color.purple

VMA = ma(V, len, maTypeInput)
//SMA = ma(S, len, maTypeInput)

trend = VMA[1] > VMA
//trend2 = SMA[1] > SMA
color = trend ? col2 : col1
//color2 = trend2 ? col4 : col3
plot(VMA, "Velocity-based MA", color=color, linewidth = 2)
//plot(SMA, "Speed-based MA", color=color2, linewidth = 2)

