RicardoSantos

[RS]Multiple Moving Averages System V3

Multiple moving averages system with color coding and hardcoded lengths based on time frame, if you have any suggestions feel free to post or pm.
Open-source script

In true TradingView spirit, the author of this script has published it open-source, so traders can understand and verify it. Cheers to the author! You may use it for free, but reuse of this code in a publication is governed by House Rules. You can favorite it to use it on a chart.

Disclaimer

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.

Want to use this script on a chart?
study(title="[RS]Multiple Moving Averages System V3", shorttitle="[RS]MMAS.V3", overlay=true)
useDPO = input(true)
src = ohlc4

ma_length00 = period == "1" ? 15 : 
        period == "5" ? 24 : // 2 hours
        period == "15" ? 12 : 
        period == "30" ? 8 : 
        period == "45" ? 8 : 
        period == "60" ? 24 : 
        period == "120" ? 12 : 
        period == "240" ? 6 : 
        period == "D" ? 5 : 
        period == "W" ? 4 : 
        period == "M" ? 6 : 13

ma_length01 = period == "1" ? 60 : 
        period == "5" ? 288 : // 1 day
        period == "15" ? 48 : 
        period == "30" ? 48 : 
        period == "45" ? 32 : 
        period == "60" ? 120 : 
        period == "120" ? 58 : 
        period == "240" ? 30 : 
        period == "D" ? 20 : 
        period == "W" ? 12 : 
        period == "M" ? 24 : 34

ma_length02 = period == "1" ? 1440 : 
        period == "5" ? 1440 : // 1 week
        period == "15" ? 480 : 
        period == "30" ? 240 : 
        period == "45" ? 160 : 
        period == "60" ? 576 : // 1 month
        period == "120" ? 240 : 
        period == "240" ? 120 : 
        period == "D" ? 60 : 
        period == "W" ? 52 : 
        period == "M" ? 60 : 144


ema1 = sma(src, ma_length00)
ema2 = sma(src, ma_length01)
ema3 = sma(src, ma_length02)

// ma color system:
c(ma) => ma < close ? green : maroon

p1 = plot(ema1, color=c(ema1), linewidth=3, title="ma1")
p2 = plot(ema2, color=c(ema2), linewidth=3, title="ma2")
p3 = plot(ema3, color=c(ema3), linewidth=3, title="ma3")

// ||------------------------------------------||
// ||---    DPO Weighted MA & Bar Colors    ---||
// ||------------------------------------------||

// DPO
dpo_weight = input(0.125)
dpo_length = round(1 + ma_length00 / 10)
dpo_src = ohlc4

dpo_disp = (dpo_src - sma(dpo_src[round(dpo_length/2) + 1], dpo_length))
dpo = (dpo_src - sma(dpo_src, dpo_length))

dpo_f = (dpo / dpo_src) * 1
dpo_df = (dpo_disp / dpo_src) * 1

dpo_trend = dpo_df - dpo_f
dpo_cycle = dpo_trend + dpo_df

dpo_diff = dpo_cycle-dpo_trend

// ma
ma1 = sma(dpo_src, dpo_length)
ma2 = sma(ma1 + (ma1 * (dpo_diff-dpo_trend))*dpo_weight, 6) 

bgsrc = useDPO ? dpo_src : sma(src, dpo_length)
plot(bgsrc, color=silver, linewidth=1)

bc = bgsrc > ma2 and ema1 < ohlc4 ?
        close > open ? lime : green :
        bgsrc < ma2 and ema1 > ohlc4 ?
        close > open ? red : maroon :
        close > open ? silver : gray

barcolor(bc)