Steve
Steve

Reputation: 1

Changin input values depending on timeframe

Will very much appreciate assisstance with coding automatic value change depending on the timeframe of the chart (namely, "mgPeriod" in below script - hitting "undeclared identifier error). Thank you in advance for the help!

//@test
study("MDR custom", overlay=true)

isDaily = timeframe.isdaily

tClose = security(tickerid, period, close)
tOpen = security(tickerid, period, open)

mgPeriod = input(14, title = "Period length", minval=1)
mgEnvelopes = input(defval = true, title = "Use High/Low envelopes?", type = bool)

if isDaily
    mgPeriod := 2

mgAvgClose = na(mgAvgClose[1]) ? ema(tClose, mgPeriod) : mgAvgClose[1] + (tClose - mgAvgClose[1]) / ((mgPeriod/2) * pow(tClose/mgAvgClose[1], 4))
mgAvgOpen = na(mgAvgOpen[1]) ? ema(tOpen, mgPeriod) : mgAvgOpen[1] + (tOpen - mgAvgOpen[1]) / ((mgPeriod/2) * pow(tOpen/mgAvgOpen[1], 4))

mgAvgOpenPlot = mgEnvelopes == true ? mgAvgOpen : na
mgClosePlot = plot(mgAvgClose ? mgAvgClose : na, title = "McGinley Moving Average", color = white, transp = 0, style = cross, linewidth = 2, join = true)
mgOpenPlot = plot(mgAvgOpenPlot ? mgAvgOpenPlot : na, title = "McGinley Moving Average", color = yellow,  transp = 0, style = cross, linewidth = 2, join = true)
fill(mgOpenPlot, mgClosePlot, color = mgAvgOpen > mgAvgClose ? yellow : white, transp = 70)

Upvotes: 0

Views: 15

Answers (0)

Related Questions