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

//@version=5
indicator("consensio", overlay=true)

// MA inputs
short = input(2, "Short MA")
mid = input(7, "Mid MA")
long = input(30, "Long MA")

// MA
s = ta.sma(close, short)
m = ta.sma(close, mid)
l = ta.sma(close, long)

// Plot MA
plot(s, "SHORT", color.lime, linewidth=1)
plot(m, "MID", color.orange, linewidth=1)
plot(l, "LONG", color.blue, linewidth=1)
    

// Label direction function
direction(txt, label_color) =>
    _label = label.new(bar_index, na)
    label.set_text(_label, txt)
    label.set_textcolor(_label, label_color)
    label.set_yloc(_label, yloc.abovebar)
    label.set_style(_label, label.style_none)
    

// Bullish candle conditions
if (l > l[1] and m > m[1] and s > s[1])
    direction("4", color.green)
if (l > l[1] and m < m[1] and s > s[1])
    direction("3", color.green)
if (l > l[1] and m > m[1] and s < s[1])
    direction("2", color.green)
if (l > l[1] and m < m[1] and s < s[1])
    direction("1", color.green)

// Bearish candle conditions
if (l < l[1] and m > m[1] and s > s[1])
    direction("1", color.red)
if (l < l[1] and m < m[1] and s > s[1])
    txt = label.new(bar_index, na)
    direction("2", color.red)
if (l < l[1] and m > m[1] and s < s[1])
    direction("3", color.red)
if (l < l[1] and m < m[1] and s < s[1])
    direction("4", color.red)

//add signal function
signal(label_color) =>
    _label = label.new(bar_index, na)
    label.set_color(_label, label_color)
    label.set_yloc(_label, yloc.belowbar)
    label.set_style(_label, label.style_diamond)

// signal conditions
if l > m and l[1] < m[1]
    signal(color.red)
if s > l and s[1] < l [1] and m < l
    signal(color.orange)
if s < l and s[1] > l[1] and m > l
    signal(color.orange)
if s < m and s[1] > m[1] and m > l
    signal(color.yellow)
if s > m and s[1] < m[1] and m > l
    signal(color.green)
if l < m and l[1] > m[1] and s > m
    signal(color.green)
    
