Bears Bulls Impulse
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ThiagoSchmitz

//@version=5
indicator("Bears Bulls Impulse")

// ———————————————————— Inputs {

int lwma_period = input.int(13, "LWMA Period", minval=1)
int lwma_weight = input.int(1, "LWMA Weight", minval=1)
float srcInput = input.source(hlc3, "Source")

// }


// ———————————————————— Functions {

// @function    Get the value of Linear-weighted Moving Average
// @param       (src source) Source for the calculation. Default is hlc3
// @param       (period int) Lookback period to be get the LWMA
// @param       (weight int) Amount of weight to be use on the LWMA calculation
// @returns     (float) A float variable reflecting the LWMA value
get_lwma(src,period, weight) =>
    sub = (weight/period)-1
    float p = na
    float d = na
    float sum = 0
    float divider = 0
    for i = 0 to period-1
        p := src[i] * ((weight-i)-sub)
        d := (weight-i)-sub
        sum := sum + p
        divider := divider + d
    sum / divider

// }


// ———————————————————— Calculations and Plots {

lwma = get_lwma(srcInput, lwma_period, lwma_weight)
color histColor = (low - lwma) + (high - lwma) >= 0 ? color.green : color.red
plot(1, "Bulls Bears", histColor, 2, plot.style_histogram)

// }
