MultiMoves
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// ©SignalFI
// Modified by ©s3raphic
//@version=5


indicator("MultiMoves", overlay=true, max_labels_count = 500, max_lines_count = 500, max_boxes_count = 500)


// MultiMoves Short{{

mm_gr_name = "MultiMoves Short"
len = input.int(55, "MM Length", group=mm_gr_name)
bullcol = input.color(#3179f5, "Bullish Color", group=mm_gr_name)
bearcol = input.color(#f7525f, "Bearish Color", group=mm_gr_name)

ma1 = ta.hma(close, len)
ma2 = ta.ema(close, len)
ma3 = ta.vwma(close,len)
ma4 = ta.linreg(close, len, 1)


bull1 = close > ma1 ? 1 : 0
bull2 = close > ma2 ? 1 : 0
bull3 = close > ma3 ? 1 : 0
bull4 = close > ma4 ? 1 : 0

bear1 = close < ma1 ? -1 : 0
bear2 = close < ma2 ? -1 : 0
bear3 = close < ma3 ? -1 : 0
bear4 = close < ma4 ? -1 : 0


bulltotal = bull1 + bull2 + bull3 + bull4
beartotal = bear1 + bear2 + bear3 + bear4

avg = math.avg(ma1, ma2, ma3, ma4)

plot(avg, color = bulltotal == 4 ? color.new(bullcol,40) : na, linewidth = 4)
plot(avg, color = bulltotal == 3 ? color.new(bullcol,55) : na, linewidth = 3)
plot(avg, color = bulltotal == 2 ? color.new(bullcol,70) : na, linewidth = 2)
plot(avg, color = bulltotal == 1 ? color.new(bullcol,85) : na, linewidth = 1)
avg_plot = plot(avg, color = na)
plot(avg, color = beartotal == -4 ? color.new(bearcol,40) : na, linewidth = 4)
plot(avg, color = beartotal == -3 ? color.new(bearcol,55) : na, linewidth = 3)
plot(avg, color = beartotal == -2 ? color.new(bearcol,70) : na, linewidth = 2)
plot(avg, color = beartotal == -1 ? color.new(bearcol,85) : na, linewidth = 1)

ma1_plot = plot(ma1, color = na)
ma2_plot = plot(ma2, color = na)
ma3_plot = plot(ma3, color = na)
ma4_plot = plot(ma4, color = na)

fill(ma1_plot, avg_plot, color = input.color(color.new(#5b9cf6, 70), "Moving Average 1", group=mm_gr_name))
fill(ma2_plot, avg_plot, color = input.color(color.new(#f7525f, 70), "Moving Average 2", group=mm_gr_name))
fill(ma3_plot, avg_plot, color = input.color(color.new(#f7525f, 70), "Moving Average 3", group=mm_gr_name))
fill(ma4_plot, avg_plot, color = input.color(color.new(#5b9cf6, 70), "Moving Average 4", group=mm_gr_name))
//}


//========================================================================================================================================================


// MultiMoves Long{

mm_gr_name2 = "MultiMoves Long"
len2 = input.int(200, "MM Length", group=mm_gr_name2)
bullcol2 = input.color(#0099ff, "Bullish Color", group=mm_gr_name2)
bearcol2 = input.color(#FF0000, "Bearish Color", group=mm_gr_name2)

ma11 = ta.hma(close, len2)
ma22 = ta.ema(close, len2)
ma33 = ta.vwma(close, len2)
ma44 = ta.linreg(close, len2, 1)


bull11 = close > ma11 ? 1 : 0
bull22 = close > ma22 ? 1 : 0
bull33 = close > ma33 ? 1 : 0
bull44 = close > ma44 ? 1 : 0

bear11 = close < ma11 ? -1 : 0
bear22 = close < ma22 ? -1 : 0
bear33 = close < ma33 ? -1 : 0
bear44 = close < ma44 ? -1 : 0


bulltotal2 = bull11 + bull22 + bull33 + bull44
beartotal2 = bear11 + bear22 + bear33 + bear44

avg2 = math.avg(ma11, ma22, ma33, ma44)

plot(avg2, color = bulltotal2 == 4 ? color.new(bullcol2,10) : na, linewidth = 4)
plot(avg2, color = bulltotal2 == 3 ? color.new(bullcol2,30) : na, linewidth = 3)
plot(avg2, color = bulltotal2 == 2 ? color.new(bullcol2,50) : na, linewidth = 2)
plot(avg2, color = bulltotal2 == 1 ? color.new(bullcol2,70) : na, linewidth = 1)
avg_plot2 = plot(avg2, color = na)
plot(avg2, color = beartotal2 == -4 ? color.new(bearcol2,10) : na, linewidth = 4)
plot(avg2, color = beartotal2 == -3 ? color.new(bearcol2,30) : na, linewidth = 3)
plot(avg2, color = beartotal2 == -2 ? color.new(bearcol2,50) : na, linewidth = 2)
plot(avg2, color = beartotal2 == -1 ? color.new(bearcol2,70) : na, linewidth = 1)

ma11_plot = plot(ma11, color = na)
ma22_plot = plot(ma22, color = na)
ma33_plot = plot(ma33, color = na)
ma44_plot = plot(ma44, color = na)

fill(ma11_plot, avg_plot2, color = input.color(color.new(#ffffff, 70), "Moving Average 1", group=mm_gr_name2))
fill(ma22_plot, avg_plot2, color = input.color(color.new(#5d606b, 70), "Moving Average 2", group=mm_gr_name2))
fill(ma33_plot, avg_plot2, color = input.color(color.new(#5d606b, 70), "Moving Average 3", group=mm_gr_name2))
fill(ma44_plot, avg_plot2, color = input.color(color.new(#ffffff, 70), "Moving Average 4", group=mm_gr_name2))
//}

//========================================================================================================================================================

// Bar Color {

long4 = bulltotal == 4
long3 = bulltotal == 3
long2 = bulltotal == 2
long1 = bulltotal == 1
short4 = beartotal == -4
short3 = beartotal == -3
short2 = beartotal == -2
short1 = beartotal == -1

barcolor(long1 ? color.new(bullcol2, 70) : long2 ? color.new(bullcol2, 50) : long3 ? color.new(bullcol2, 30) : long4 ? color.new(bullcol2, 10) : short1 ? color.new(bearcol2, 70) : short2 ? color.new(bearcol2, 50) : short3 ? color.new(bearcol2, 30) : short4 ? color.new(bearcol2, 10) : na)

//}

//========================================================================================================================================================

// Crossover Alerts {	

alertcondition(ta.crossover(avg, avg2), title = "Crossover", message = "MultiMoves Crossover")
alertcondition(ta.crossunder(avg, avg2), title = "Crossunder", message = "MultiMoves Crossunder")

//}}