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

//@version=4
study("Fishnet", "FISH", true)

// Inputs
movingAverageType      = input("sma", "Moving average type", options = ["sma", "ema"])
lowestMovingAverage    = input(5, "Lowest moving average length", minval = 1)
stepSize               = input(5, "Step size in between the moving averages", minval = 1)
numberOfMovingAverages = input(25, "Number of moving averages (1 - 64)", minval = 1, maxval = 64)
linewidth              = input(2, "Linewidth (1 - 4)", minval = 1, maxval = 4)

movingAverage(type, closePrice, timePeriod) =>
    if type == "sma"
        sma(closePrice, timePeriod)
    else if type == "ema"
        ema(closePrice, timePeriod)

color0 = color.new(#CCCCCC, 50)
initialMovingAverage = movingAverage(movingAverageType, close, lowestMovingAverage)

plot(numberOfMovingAverages < 1   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 1) * stepSize) , "", color.new(#FC0010, 50), linewidth)
plot(numberOfMovingAverages < 2   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 2) * stepSize) , "", color.new(#FC0410, 50), linewidth)
plot(numberOfMovingAverages < 3   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 3) * stepSize) , "", color.new(#FC0810, 50), linewidth)
plot(numberOfMovingAverages < 4   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 4) * stepSize) , "", color.new(#FC0C10, 50), linewidth)
plot(numberOfMovingAverages < 5   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 5) * stepSize) , "", color.new(#FC1010, 50), linewidth)
plot(numberOfMovingAverages < 6   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 6) * stepSize) , "", color.new(#FC1410, 50), linewidth)
plot(numberOfMovingAverages < 7   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 7) * stepSize) , "", color.new(#FC1810, 50), linewidth)
plot(numberOfMovingAverages < 8   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 8) * stepSize) , "", color.new(#FC1C10, 50), linewidth)
plot(numberOfMovingAverages < 9   ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 9) * stepSize) , "", color.new(#FC2010, 50), linewidth)
plot(numberOfMovingAverages < 10  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 10)* stepSize) , "", color.new(#FC2410, 50), linewidth)
plot(numberOfMovingAverages < 11  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 11)* stepSize) , "", color.new(#FC2810, 50), linewidth)
plot(numberOfMovingAverages < 12  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 12)* stepSize) , "", color.new(#FC2C10, 50), linewidth)
plot(numberOfMovingAverages < 13  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 13)* stepSize) , "", color.new(#FC3010, 50), linewidth)
plot(numberOfMovingAverages < 14  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 14)* stepSize) , "", color.new(#FC3410, 50), linewidth)
plot(numberOfMovingAverages < 15  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 15)* stepSize) , "", color.new(#FC3810, 50), linewidth)
plot(numberOfMovingAverages < 16  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 16)* stepSize) , "", color.new(#FC3C10, 50), linewidth)
plot(numberOfMovingAverages < 17  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 17)* stepSize) , "", color.new(#FC4010, 50), linewidth)
plot(numberOfMovingAverages < 18  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 18)* stepSize) , "", color.new(#FC4410, 50), linewidth)
plot(numberOfMovingAverages < 19  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 19)* stepSize) , "", color.new(#FC4810, 50), linewidth)
plot(numberOfMovingAverages < 20  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 20)* stepSize) , "", color.new(#FC4C10, 50), linewidth)
plot(numberOfMovingAverages < 21  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 21)* stepSize) , "", color.new(#FC5010, 50), linewidth)
plot(numberOfMovingAverages < 22  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 22)* stepSize) , "", color.new(#FC5410, 50), linewidth)
plot(numberOfMovingAverages < 23  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 23)* stepSize) , "", color.new(#FC5810, 50), linewidth)
plot(numberOfMovingAverages < 24  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 24)* stepSize) , "", color.new(#FC5C10, 50), linewidth)
plot(numberOfMovingAverages < 25  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 25)* stepSize) , "", color.new(#FC6010, 50), linewidth)
plot(numberOfMovingAverages < 26  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 26)* stepSize) , "", color.new(#FC6410, 50), linewidth)
plot(numberOfMovingAverages < 27  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 27)* stepSize) , "", color.new(#FC6810, 50), linewidth)
plot(numberOfMovingAverages < 28  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 28)* stepSize) , "", color.new(#FC6C10, 50), linewidth)
plot(numberOfMovingAverages < 29  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 29)* stepSize) , "", color.new(#FC7010, 50), linewidth)
plot(numberOfMovingAverages < 30  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 30)* stepSize) , "", color.new(#FC7410, 50), linewidth)
plot(numberOfMovingAverages < 31  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 31)* stepSize) , "", color.new(#FC7810, 50), linewidth)
plot(numberOfMovingAverages < 32  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 32)* stepSize) , "", color.new(#FC7C10, 50), linewidth)
plot(numberOfMovingAverages < 33  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 33)* stepSize) , "", color.new(#FC8010, 50), linewidth)
plot(numberOfMovingAverages < 34  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 34)* stepSize) , "", color.new(#FC8410, 50), linewidth)
plot(numberOfMovingAverages < 35  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 35)* stepSize) , "", color.new(#FC8810, 50), linewidth)
plot(numberOfMovingAverages < 36  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 36)* stepSize) , "", color.new(#FC8C10, 50), linewidth)
plot(numberOfMovingAverages < 37  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 37)* stepSize) , "", color.new(#FC9010, 50), linewidth)
plot(numberOfMovingAverages < 38  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 38)* stepSize) , "", color.new(#FC9410, 50), linewidth)
plot(numberOfMovingAverages < 39  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 39)* stepSize) , "", color.new(#FC9810, 50), linewidth)
plot(numberOfMovingAverages < 40  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 40)* stepSize) , "", color.new(#FC9C10, 50), linewidth)
plot(numberOfMovingAverages < 41  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 41)* stepSize) , "", color.new(#FCA010, 50), linewidth)
plot(numberOfMovingAverages < 42  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 42)* stepSize) , "", color.new(#FCA410, 50), linewidth)
plot(numberOfMovingAverages < 43  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 43)* stepSize) , "", color.new(#FCA810, 50), linewidth)
plot(numberOfMovingAverages < 44  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 44)* stepSize) , "", color.new(#FCAC10, 50), linewidth)
plot(numberOfMovingAverages < 45  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 45)* stepSize) , "", color.new(#FCB010, 50), linewidth)
plot(numberOfMovingAverages < 46  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 46)* stepSize) , "", color.new(#FCB410, 50), linewidth)
plot(numberOfMovingAverages < 47  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 47)* stepSize) , "", color.new(#FCB810, 50), linewidth)
plot(numberOfMovingAverages < 48  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 48)* stepSize) , "", color.new(#FCBC10, 50), linewidth)
plot(numberOfMovingAverages < 49  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 49)* stepSize) , "", color.new(#FCC010, 50), linewidth)
plot(numberOfMovingAverages < 50  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 50)* stepSize) , "", color.new(#FCC410, 50), linewidth)
plot(numberOfMovingAverages < 51  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 51)* stepSize) , "", color.new(#FCC810, 50), linewidth)
plot(numberOfMovingAverages < 52  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 52)* stepSize) , "", color.new(#FCCC10, 50), linewidth)
plot(numberOfMovingAverages < 53  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 53)* stepSize) , "", color.new(#FCD010, 50), linewidth)
plot(numberOfMovingAverages < 54  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 54)* stepSize) , "", color.new(#FCD410, 50), linewidth)
plot(numberOfMovingAverages < 55  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 55)* stepSize) , "", color.new(#FCD810, 50), linewidth)
plot(numberOfMovingAverages < 56  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 56)* stepSize) , "", color.new(#FCDC10, 50), linewidth)
plot(numberOfMovingAverages < 57  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 57)* stepSize) , "", color.new(#FCE010, 50), linewidth)
plot(numberOfMovingAverages < 58  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 58)* stepSize) , "", color.new(#FCE410, 50), linewidth)
plot(numberOfMovingAverages < 59  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 59)* stepSize) , "", color.new(#FCE810, 50), linewidth)
plot(numberOfMovingAverages < 60  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 60)* stepSize) , "", color.new(#FCEC10, 50), linewidth)
plot(numberOfMovingAverages < 61  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 61)* stepSize) , "", color.new(#FCF010, 50), linewidth)
plot(numberOfMovingAverages < 62  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 62)* stepSize) , "", color.new(#FCF410, 50), linewidth)
plot(numberOfMovingAverages < 63  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 63)* stepSize) , "", color.new(#FCF810, 50), linewidth)
plot(numberOfMovingAverages < 64  ? na : movingAverage(movingAverageType, close, (lowestMovingAverage + 64)* stepSize) , "", color.new(#FCFC10, 50), linewidth)
