Probability Cloud BASIC [@AndorraInvestor]
// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// ©AndorraInvestor

// On Twitter:                 _                      _____                     _             
//    ____     /\             | |                    |_   _|                   | |            
//   / __ \   /  \   _ __   __| | ___  _ __ _ __ __ _  | |  _ ____   _____  ___| |_ ___  _ __ 
//  / / _` | / /\ \ | '_ \ / _` |/ _ \| '__| '__/ _` | | | | '_ \ \ / / _ \/ __| __/ _ \| '__|
// | | (_| |/ ____ \| | | | (_| | (_) | |  | | | (_| |_| |_| | | \ V /  __/\__ \ || (_) | |   
//  \ \__,_/_/    \_\_| |_|\__,_|\___/|_|  |_|  \__,_|_____|_| |_|\_/ \___||___/\__\___/|_|   
//   \____/                                                                                   
//

//@version=5

indicator("🔮☁️ Probability Cloud BASIC [@AndorraInvestor]", overlay=true)


//==================================================================================================
// Thanks to u/Electrified for letting me use some of his work as starting point for my first script
//==================================================================================================
import Electrified/MovingAverages/10 as MA
import Electrified/DataCleaner/7 as Data



SMA = 'SMA', EMA = 'EMA', WMA = 'WMA', VWMA = 'VWMA', VAWMA = 'VAWMA'
cloudcol = input(color.new(color.blue,98), "Cloud Color")
var type = input.string(WMA, "Mode", options=[SMA,EMA,WMA,VWMA,VAWMA])
src = input.source(hl2, "Source")


var len1 = 5
var len2 = 10
var len3 = 15
var len4 = 20
var len5 = 25
var len6 = 30
var len7 = 35
var len8 = 40
var len9 = 45
var len10 = 50
var len11 = 55
var len12 = 60
var len13 = 65
var len14 = 70
var len15 = 75
var len16 = 80
var len17 = 85
var len18 = 90
var len19 = 95
var len20 = 100



ma1 = MA.get(type, len1, src)
ma2 = MA.get(type, len2, src)
ma3 = MA.get(type, len3, src)
ma4 = MA.get(type, len4, src)
ma5 = MA.get(type, len5, src)
ma6 = MA.get(type, len6, src)
ma7 = MA.get(type, len7, src)
ma8 = MA.get(type, len8, src)
ma9 = MA.get(type, len9, src)
ma10 = MA.get(type, len10, src)
ma11 = MA.get(type, len11, src)
ma12 = MA.get(type, len12, src)
ma13 = MA.get(type, len13, src)
ma14 = MA.get(type, len14, src)
ma15 = MA.get(type, len15, src)
ma16 = MA.get(type, len16, src)
ma17 = MA.get(type, len17, src)
ma18 = MA.get(type, len18, src)
ma19 = MA.get(type, len19, src)
ma20 = MA.get(type, len20, src)


ma_d1 = (src - ma1)/ma1
ma_d2 = (src - ma2)/ma2
ma_d3 = (src - ma3)/ma3
ma_d4 = (src - ma4)/ma4
ma_d5 = (src - ma5)/ma5
ma_d6 = (src - ma6)/ma6
ma_d7 = (src - ma7)/ma7
ma_d8 = (src - ma8)/ma8
ma_d9 = (src - ma9)/ma9
ma_d10 = (src - ma10)/ma10
ma_d11 = (src - ma11)/ma11
ma_d12 = (src - ma12)/ma12
ma_d13 = (src - ma13)/ma13
ma_d14 = (src - ma14)/ma14
ma_d15 = (src - ma15)/ma15
ma_d16 = (src - ma16)/ma16
ma_d17 = (src - ma17)/ma17
ma_d18 = (src - ma18)/ma18
ma_d19 = (src - ma19)/ma19
ma_d20 = (src - ma20)/ma20


//In this BASIC version number of outliers is fixed to 4
cleaned1 = Data.naOutliers(ma_d1, len1, 4)
cleaned2 = Data.naOutliers(ma_d2, len2, 4)
cleaned3 = Data.naOutliers(ma_d3, len3, 4)
cleaned4 = Data.naOutliers(ma_d4, len4, 4)
cleaned5 = Data.naOutliers(ma_d5, len5, 4)
cleaned6 = Data.naOutliers(ma_d6, len6, 4)
cleaned7 = Data.naOutliers(ma_d7, len7, 4)
cleaned8 = Data.naOutliers(ma_d8, len8, 4)
cleaned9 = Data.naOutliers(ma_d9, len9, 4)
cleaned10 = Data.naOutliers(ma_d10, len10, 4)
cleaned11 = Data.naOutliers(ma_d11, len11, 4)
cleaned12 = Data.naOutliers(ma_d12, len12, 4)
cleaned13 = Data.naOutliers(ma_d13, len13, 4)
cleaned14 = Data.naOutliers(ma_d14, len14, 4)
cleaned15 = Data.naOutliers(ma_d15, len15, 4)
cleaned16 = Data.naOutliers(ma_d16, len16, 4)
cleaned17 = Data.naOutliers(ma_d17, len17, 4)
cleaned18 = Data.naOutliers(ma_d18, len18, 4)
cleaned19 = Data.naOutliers(ma_d19, len19, 4)
cleaned20 = Data.naOutliers(ma_d20, len20, 4)


avg1 = ta.sma(cleaned1, len1) * ma1
stdev1 = ta.stdev(cleaned1, len1) * ma1
avg2 = ta.sma(cleaned2, len2) * ma2
stdev2 = ta.stdev(cleaned2, len2) * ma2
avg3 = ta.sma(cleaned3, len3) * ma3
stdev3 = ta.stdev(cleaned3, len3) * ma3
avg4 = ta.sma(cleaned4, len4) * ma4
stdev4 = ta.stdev(cleaned4, len4) * ma4
avg5 = ta.sma(cleaned5, len5) * ma5
stdev5 = ta.stdev(cleaned5, len5) * ma5
avg6 = ta.sma(cleaned6, len6) * ma6
stdev6 = ta.stdev(cleaned6, len6) * ma6
avg7 = ta.sma(cleaned7, len7) * ma7
stdev7 = ta.stdev(cleaned7, len7) * ma7
avg8 = ta.sma(cleaned8, len8) * ma8
stdev8 = ta.stdev(cleaned8, len8) * ma8
avg9 = ta.sma(cleaned9, len9) * ma9
stdev9 = ta.stdev(cleaned9, len9) * ma9
avg10 = ta.sma(cleaned10, len10) * ma10
stdev10 = ta.stdev(cleaned10, len10) * ma10
avg11 = ta.sma(cleaned11, len11) * ma11
stdev11 = ta.stdev(cleaned11, len11) * ma11
avg12 = ta.sma(cleaned12, len12) * ma12
stdev12 = ta.stdev(cleaned12, len12) * ma12
avg13 = ta.sma(cleaned13, len13) * ma13
stdev13 = ta.stdev(cleaned13, len13) * ma13
avg14 = ta.sma(cleaned14, len14) * ma14
stdev14 = ta.stdev(cleaned14, len14) * ma14
avg15 = ta.sma(cleaned15, len15) * ma15
stdev15 = ta.stdev(cleaned15, len15) * ma15
avg16 = ta.sma(cleaned16, len16) * ma16
stdev16 = ta.stdev(cleaned16, len16) * ma16
avg17 = ta.sma(cleaned17, len17) * ma17
stdev17 = ta.stdev(cleaned17, len17) * ma17
avg18 = ta.sma(cleaned18, len18) * ma18
stdev18 = ta.stdev(cleaned18, len18) * ma18
avg19 = ta.sma(cleaned19, len19) * ma19
stdev19 = ta.stdev(cleaned19, len19) * ma19
avg20 = ta.sma(cleaned20, len20) * ma20
stdev20 = ta.stdev(cleaned20, len20) * ma20


upper1 = ma1 + avg1 + stdev1
lower1 = ma1 + avg1 - stdev1
upper2 = ma2 + avg2 + stdev2
lower2 = ma2 + avg2 - stdev2
upper3 = ma3 + avg3 + stdev3
lower3 = ma3 + avg3 - stdev3
upper4 = ma4 + avg4 + stdev4
lower4 = ma4 + avg4 - stdev4
upper5 = ma5 + avg5 + stdev5
lower5 = ma5 + avg5 - stdev5
upper6 = ma6 + avg6 + stdev6
lower6 = ma6 + avg6 - stdev6
upper7 = ma7 + avg7 + stdev7
lower7 = ma7 + avg7 - stdev7
upper8 = ma8 + avg8 + stdev8
lower8 = ma8 + avg8 - stdev8
upper9 = ma9 + avg9 + stdev9
lower9 = ma9 + avg9 - stdev9
upper10 = ma10 + avg10 + stdev10
lower10 = ma10 + avg10 - stdev10
upper11 = ma11 + avg11 + stdev11
lower11 = ma11 + avg11 - stdev11
upper12 = ma12 + avg12 + stdev12
lower12 = ma12 + avg12 - stdev12
upper13 = ma13 + avg13 + stdev13
lower13 = ma13 + avg13 - stdev13
upper14 = ma14 + avg14 + stdev14
lower14 = ma14 + avg14 - stdev14
upper15 = ma15 + avg15 + stdev15
lower15 = ma15 + avg15 - stdev15
upper16 = ma16 + avg16 + stdev16
lower16 = ma16 + avg16 - stdev16
upper17 = ma17 + avg17 + stdev17
lower17 = ma17 + avg17 - stdev17
upper18 = ma18 + avg18 + stdev18
lower18 = ma18 + avg18 - stdev18
upper19 = ma19 + avg19 + stdev19
lower19 = ma19 + avg19 - stdev19
upper20 = ma20 + avg20 + stdev20
lower20 = ma20 + avg20 - stdev20


//The "display=dispplay.none" is the best solution to the "Maximum number of output series" error, which was reached once color was an added input variable.
pUpper1 = plot(upper1 + stdev1, display=display.none)
pLower1 = plot(lower1 - stdev1, display=display.none)
pUpper2 = plot(upper2 + stdev2, display=display.none)
pLower2 = plot(lower2 - stdev2, display=display.none)
pUpper3 = plot(upper3 + stdev3, display=display.none)
pLower3 = plot(lower3 - stdev3, display=display.none)
pUpper4 = plot(upper4 + stdev4, display=display.none)
pLower4 = plot(lower4 - stdev4, display=display.none)
pUpper5 = plot(upper5 + stdev5, display=display.none)
pLower5 = plot(lower5 - stdev5, display=display.none)
pUpper6 = plot(upper6 + stdev6, display=display.none)
pLower6 = plot(lower6 - stdev6, display=display.none)
pUpper7 = plot(upper7 + stdev7, display=display.none)
pLower7 = plot(lower7 - stdev7, display=display.none)
pUpper8 = plot(upper8 + stdev8, display=display.none)
pLower8 = plot(lower8 - stdev8, display=display.none)
pUpper9 = plot(upper9 + stdev9, display=display.none)
pLower9 = plot(lower9 - stdev9, display=display.none)
pUpper10 = plot(upper10 + stdev10, display=display.none)
pLower10 = plot(lower10 - stdev10, display=display.none)
pUpper11 = plot(upper11 + stdev11, display=display.none)
pLower11 = plot(lower11 - stdev11, display=display.none)
pUpper12 = plot(upper12 + stdev12, display=display.none)
pLower12 = plot(lower12 - stdev12, display=display.none)
pUpper13 = plot(upper13 + stdev13, display=display.none)
pLower13 = plot(lower13 - stdev13, display=display.none)
pUpper14 = plot(upper14 + stdev14, display=display.none)
pLower14 = plot(lower14 - stdev14, display=display.none)
pUpper15 = plot(upper15 + stdev15, display=display.none)
pLower15 = plot(lower15 - stdev15, display=display.none)
pUpper16 = plot(upper16 + stdev16, display=display.none)
pLower16 = plot(lower16 - stdev16, display=display.none)
pUpper17 = plot(upper17 + stdev17, display=display.none)
pLower17 = plot(lower17 - stdev17, display=display.none)
pUpper18 = plot(upper18 + stdev18, display=display.none)
pLower18 = plot(lower18 - stdev18, display=display.none)
pUpper19 = plot(upper19 + stdev19, display=display.none)
pLower19 = plot(lower19 - stdev19, display=display.none)
pUpper20 = plot(upper20 + stdev20, display=display.none)
pLower20 = plot(lower20 - stdev20, display=display.none)


fill(pUpper1, pLower1, cloudcol)
fill(pUpper2, pLower2, cloudcol)
fill(pUpper3, pLower3, cloudcol)
fill(pUpper4, pLower4, cloudcol)
fill(pUpper5, pLower5, cloudcol)
fill(pUpper6, pLower6, cloudcol)
fill(pUpper7, pLower7, cloudcol)
fill(pUpper8, pLower8, cloudcol)
fill(pUpper9, pLower9, cloudcol)
fill(pUpper10, pLower10, cloudcol)
fill(pUpper11, pLower11, cloudcol)
fill(pUpper12, pLower12, cloudcol)
fill(pUpper13, pLower13, cloudcol)
fill(pUpper14, pLower14, cloudcol)
fill(pUpper15, pLower15, cloudcol)
fill(pUpper16, pLower16, cloudcol)
fill(pUpper17, pLower17, cloudcol)
fill(pUpper18, pLower18, cloudcol)
fill(pUpper19, pLower19, cloudcol)
fill(pUpper20, pLower20, cloudcol)
fill(pUpper17, pLower17, cloudcol)
fill(pUpper18, pLower18, cloudcol)
fill(pUpper19, pLower19, cloudcol)
fill(pUpper20, pLower20, cloudcol)
