RicardoSantos

[RS]Multiple Moving Averages System V3

1057 7 203
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.
Remove from Favorite Scripts Add to Favorite Scripts
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)
Would it be difficult to add an input option so that I can adjust the MA lengths used? I figured out how to do it in the source code, but saving the changes to the code resets whatever visual options I've adjusted.
+1 Reply
RicardoSantos PRO SirNoseDvoidoffunk
the reason they are hardcoded is because it would create alot inputs, if you want them to be manually replace ....
malength00, malength01, malength02 with:
malength00 = input(4)
malength01 = input(8)
malength02 = input(16)
+2 Reply
SirNoseDvoidoffunk RicardoSantos
Cool, thanks. Just prefer a quick way to move the settings around on different time frames without having to redo personalized settings and whatnot.
+1 Reply
Can you add other indicators with this color coding indication. Really helps thanks
+1 Reply
hi, what other indicators you would like to see?
+1 Reply
Maybe a stupid question... but what do the different colors mean? Both on MMA lines and candles?
Reply
pdenoeud2 PRO pdenoeud2
@pdenoeud2, I can not guess it from the code :-(
Reply
Ideas Scripts Chart
United States
United Kingdom
India
España
France
Italia
Polska
Brasil
Россия
Türkiye
Indonesia
日本
한국
Home Stock Screener Forex Signal Finder Economic Calendar How It Works Chart Features House Rules Moderators For the WEB Widgets Stock Charting Library Priority Support Feature Request Blog & News FAQ Help & Wiki Twitter
Private Messages Chat Ideas Published Followers Following Priority Support Public Profile Profile Settings Account and Billing Sign Out