Normalized LWMA Slope
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © crypteisfuture

//@version=5
indicator("Normalized LWMA Slope")

//credits to : @io72signals for lwma function
get_lwma(src,period, weight) =>
    price = src
    sub = (weight/period)-1
    float p = na
    float d = na
    float sum = 0
    float divider = 0
    for i = 0 to period-1
        p := price[i] * ((weight-i)-sub)
        d := (weight-i)-sub
        sum := sum + p
        divider := divider + d
    sum / divider
    
source = input.source(close)

atr_len = input.int(14)
atr_ = ta.atr(atr_len)

lwma_length = input.int(12)
lwma_weight = input.int(2)

lwma_ = get_lwma(source, lwma_length, lwma_weight)

// <start> logic from https://fxcodebase.com/code/viewtopic.php?f=17&t=62214

lwma = (lwma_ - lwma_[1]) / atr_

color_ = lwma > 0 ? lwma > lwma[1] ? color.new(color.lime, 0) : color.new(color.red, 0) : lwma > lwma[1] ? color.new(color.green, 0) : color.new(color.maroon, 0)

cond_ = lwma > 0 ? lwma > lwma[1] ? 2 : -1 : lwma > lwma[1] ? 1 : -2

plot(lwma, color = color_, style = plot.style_histogram)

// <end> logic from https://fxcodebase.com/code/viewtopic.php?f=17&t=62214


alertcondition(cond_ == 2, title = 'Strong Buy!', message = 'Strong Buy!')
alertcondition(cond_ == 1, title = 'Simple Buy!', message = 'Simple Buy!')

alertcondition(cond_ == -2, title = 'Strong Buy!', message = 'Strong Sell!')
alertcondition(cond_ == -1, title = 'Simple Buy!', message = 'Simple Sell!')


