Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © Hero_Hedge
- //@version=4
- study("Moving Average Cross Builder", shorttitle="MACB", overlay=true)
- //Add in minval and step size to get float vales for fib
- MA1Period = input( defval=50,title="Period of MA1", minval=0, step=1)
- MA1Type = input(title="MA1 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull", "Volume weighted", "McGinley", "Zero lag"])
- MA1Source = input(title="MA1 Source", type=input.source, defval=close)
- MA1Resolution = input(title="MA1 Resolution", type=input.resolution, defval="")
- MA1Visible = input(title="Show MA1", type=input.bool, defval=true)
- MA2Period = input(100, title="Period of MA2", minval=0, step=1)
- MA2Type = input(title="MA2 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
- MA2Source = input(title="MA2 Source", type=input.source, defval=close)
- MA2Resolution = input(title="MA2 Resolution", type=input.resolution, defval="")
- MA2Visible = input(title="Show MA2", type=input.bool, defval=false)
- MA3Period = input(150, title="Period of MA3",minval=0)
- MA3Type = input(title="MA3 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
- MA3Source = input(title="MA3 Source", type=input.source, defval=close)
- MA3Resolution = input(title="MA3 Resolution", type=input.resolution, defval="")
- MA3Visible = input(title="Show MA3", type=input.bool, defval=false)
- MA4Period = input(200, title="Period of MA4", minval=0)
- MA4Type = input(title="MA4 Type", defval="Simple", options=["Simple", "Smoothed", "Exponential", "Double Exponential", "Triple Exponential", "Weighted", "Hull","Volume weighted", "McGinley", "Zero lag"])
- MA4Source = input(title="MA4 Source", type=input.source, defval=close)
- MA4Resolution = input(title="MA4 Resolution", type=input.resolution, defval="")
- MA4Visible = input(title="Show MA4", type=input.bool, defval=false)
- ma(MAType, MASource, MAPeriod) =>
- mg = 0.0
- smma = 0.0
- if MAType == "Simple"
- sma(MASource, MAPeriod)
- else if MAType =="Exponential"
- ema(MASource, MAPeriod)
- else if MAType == "Weighted"
- wma(MASource, MAPeriod)
- else if MAType == "Hull"
- hma(MASource, MAPeriod)
- else if MAType == "Volume weighted"
- vwma(MASource, MAPeriod)
- else if MAType == "Double Exponential"
- e = ema(MASource, MAPeriod)
- 2 * e - ema(e, MAPeriod)
- else if MAType == "Triple Exponential"
- e = ema(MASource, MAPeriod)
- 3 * (e - ema(e, MAPeriod)) + ema(ema(e, MAPeriod), MAPeriod) // EVERYTHING GOOD UNTIL HERE
- else if MAType == "Smoothed"
- len = input(7, minval=1, title="Length")
- src = input(close, title="Source")
- smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
- else if MAType == "Zero lag" //script by HPotter
- xPrice = MASource
- nPeriod = MAPeriod
- xLag = (nPeriod - 1) / 2
- xEMAData = (xPrice + (xPrice - xPrice[xLag]))
- xZLEMA = ema(xEMAData, nPeriod)
- else if MAType == "McGinley"
- Mglength = MAPeriod
- source = MASource
- mg := na(mg[1]) ? ema(source, Mglength) : mg[1] + (source - mg[1]) / (Mglength * pow(source/mg[1], 4))
- else
- float(na)
- MA1 = security(syminfo.tickerid, MA1Resolution, ma(MA1Type, MA1Source, MA1Period))
- MA2 = security(syminfo.tickerid, MA2Resolution, ma(MA2Type, MA2Source, MA2Period))
- MA3 = security(syminfo.tickerid, MA3Resolution, ma(MA3Type, MA3Source, MA3Period))
- MA4 = security(syminfo.tickerid, MA4Resolution, ma(MA4Type, MA4Source, MA4Period))
- plot(MA1Visible ? MA1 : na, color=color.red, title="MA1")
- plot(MA2Visible ? MA2 : na, color=color.yellow, title="MA2")
- plot(MA3Visible ? MA3 : na, color=color.green, title="MA3")
- plot(MA4Visible ? MA4 : na, color=color.blue, title="MA4")
Add Comment
Please, Sign In to add comment