I'm trying to plot the 9/50/180 day SMA regardless of the timeframe period.
If you're looking at the candles in 1D, 4h, 3h, 15m, .. I just want to see the 9/50/.. day SMA.
If I could calculate the number of bars in a day, I could take the SMA over a 9 * #numberOfCandlesInDay length.
I could define a numberOfMinutes per syminfo.prefix (lots of work) and then calculate the number of bars based on timeframe.multiplier, but that is a hassle and prone to error.
Any tips?
Why not use security()
? This uses our f_secureSecurity()
wrapper function so that you avoid repainting:
//@version=4
study("", "MAs", true)
f_secureSecurity(_symbol, _res, _src) => security(_symbol, _res, _src[1], lookahead = barmerge.lookahead_on)
smaD9 = f_secureSecurity(syminfo.tickerid, "D", sma(close, 9))
smaD50 = f_secureSecurity(syminfo.tickerid, "D", sma(close, 50))
smaD180 = f_secureSecurity(syminfo.tickerid, "D", sma(close, 180))
plot(smaD9 )
plot(smaD50 )
plot(smaD180)
Another option is to use a ready-made indie like this one:
https://www.tradingview.com/script/8AUuFonD-5-MAs-w-alerts-LucF/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.