StudyName = "MA Cloud"\nShortStudyName = "MA cloud" \nstudy(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="")\n\nsource = input(close, title="Source")\ntypeofMA1 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])\nlength_ma1 = input(30, title = "[ALL but VWAP] Length of Moving Average 1", type=input.integer)\ntypeofMA2 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])\nlength_ma2 = input(74, title = "[ALL but VWAP] Length of Moving Average 2", type=input.integer)\n\ncolor_candles = input(true, title="Color based on trend?")\n\nf_smma(src, len) =>\n smma = 0.0\n smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len\n smma\n\nf_hullma(src, length) =>\n wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))\n\nf_tma(src, length) =>\n sma(sma(src, length), length)\n\nf_dema(src, length) =>\n emaValue = ema(src, length)\n 2 * emaValue - ema(emaValue, length)\n\nf_tema(src, length) =>\n ema1 = ema(src, length)\n ema2 = ema(ema1, length)\n ema3 = ema(ema2, length)\n (3 * ema1) - (3 * ema2) + ema3 \n\nf_ma(smoothing, src, length) =>\n\n iff(smoothing == "RMA", rma(src, length), \n iff(smoothing == "SMA", sma(src, length),\n iff(smoothing == "EMA", ema(src, length),\n iff(smoothing == "WMA", wma(src, length),\n iff(smoothing == "VWMA", vwma(src, length),\n iff(smoothing == "SMMA", f_smma(src, length),\n iff(smoothing == "HullMA", f_hullma(src, length),\n iff(smoothing == "VWAP", vwap(hlc3),\n iff(smoothing == "DEMA", f_dema(src, length),\n iff(smoothing == "TEMA", f_tema(src, length), src))))))))))\n\nMA1 = f_ma(typeofMA1, source, length_ma1)\nMA2 = f_ma(typeofMA2, source, length_ma2)\n\nplot_ma1 = plot(MA1, color=color.new(color.green, 0), linewidth=3, title = "MA1")\nplot_ma2 = plot(MA2, color=color.new(color.red, 0), linewidth=3, title = "MA2")\n\nfill_color = MA1 > MA2 ? color.new(color.green, 60) : color.new(color.red, 60)\nfill(plot_ma1, plot_ma2, color=fill_color)\n\n// Candles coloring\nclr = not color_candles ? na : \n MA1 > MA2 ? color.new(color.lime, 40) : color.new(color.fuchsia, 40)\n\nbarcolor(clr,title="Trend State Bar Colouring")\n\ncond_buy = MA1 > MA2 and crossover(MA1, MA2)\ncond_sell = MA1 < MA2 and crossunder(MA1, MA2)\n\n// green triangle\nplotshape(cond_buy, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.large)\n// red triangle\nplotshape(cond_sell, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.large)\n\n\nalertcondition(cond_buy, title='Buy Alert', message="Buy Alert")\nalertcondition(cond_sell, title='Sell Alert', message="Sell Alert")\n
\n","author":{"@type":"Person","name":"Arshia.h"},"upvoteCount":0,"answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"This is expected behavior if you calculate your script in scope of other timeframe. If you on a 60 min
chart, and setting your indicator time frame to 1D
, then you will be given just 1 value per session of your 60 min
chart.
This is the same as using security()
function. Info about this can be found here:
https://www.tradingview.com/pine-script-docs/en/v5/concepts/Other_timeframes_and_data.html#gaps
\n"Hidden" gaps
parameter (as you using security
function implicitly by using resolution
parameter) can be set in study()
function as resolution_gaps = false
:
So you need to rewrite your study call as:
\nstudy(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="", resolution_gaps = false)\n
\n","author":{"@type":"Person","name":"Starr Lucky"},"upvoteCount":1}}}Reputation: 13
I have made this indicator on trading view that fills the distance between to moving averages (and it's called a cloud) the cloud works when I don't set a specific timeframe for indicator to get the data from but for example when I put the indicators timeframe on weekly and view it on daily chart everything is right except for the cloud and it doesn't get filled in other timeframes than what you have set the whole indicator on ( in this example it only works on weekly chart and on other time frames it doesn't work) do you know what I should do to make it work?
StudyName = "MA Cloud"
ShortStudyName = "MA cloud"
study(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="")
source = input(close, title="Source")
typeofMA1 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])
length_ma1 = input(30, title = "[ALL but VWAP] Length of Moving Average 1", type=input.integer)
typeofMA2 = input(title="Type of Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "TMA", "HullMA", "DEMA", "TEMA", "VWAP"])
length_ma2 = input(74, title = "[ALL but VWAP] Length of Moving Average 2", type=input.integer)
color_candles = input(true, title="Color based on trend?")
f_smma(src, len) =>
smma = 0.0
smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len
smma
f_hullma(src, length) =>
wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
f_tma(src, length) =>
sma(sma(src, length), length)
f_dema(src, length) =>
emaValue = ema(src, length)
2 * emaValue - ema(emaValue, length)
f_tema(src, length) =>
ema1 = ema(src, length)
ema2 = ema(ema1, length)
ema3 = ema(ema2, length)
(3 * ema1) - (3 * ema2) + ema3
f_ma(smoothing, src, length) =>
iff(smoothing == "RMA", rma(src, length),
iff(smoothing == "SMA", sma(src, length),
iff(smoothing == "EMA", ema(src, length),
iff(smoothing == "WMA", wma(src, length),
iff(smoothing == "VWMA", vwma(src, length),
iff(smoothing == "SMMA", f_smma(src, length),
iff(smoothing == "HullMA", f_hullma(src, length),
iff(smoothing == "VWAP", vwap(hlc3),
iff(smoothing == "DEMA", f_dema(src, length),
iff(smoothing == "TEMA", f_tema(src, length), src))))))))))
MA1 = f_ma(typeofMA1, source, length_ma1)
MA2 = f_ma(typeofMA2, source, length_ma2)
plot_ma1 = plot(MA1, color=color.new(color.green, 0), linewidth=3, title = "MA1")
plot_ma2 = plot(MA2, color=color.new(color.red, 0), linewidth=3, title = "MA2")
fill_color = MA1 > MA2 ? color.new(color.green, 60) : color.new(color.red, 60)
fill(plot_ma1, plot_ma2, color=fill_color)
// Candles coloring
clr = not color_candles ? na :
MA1 > MA2 ? color.new(color.lime, 40) : color.new(color.fuchsia, 40)
barcolor(clr,title="Trend State Bar Colouring")
cond_buy = MA1 > MA2 and crossover(MA1, MA2)
cond_sell = MA1 < MA2 and crossunder(MA1, MA2)
// green triangle
plotshape(cond_buy, style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), size=size.large)
// red triangle
plotshape(cond_sell, style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), size=size.large)
alertcondition(cond_buy, title='Buy Alert', message="Buy Alert")
alertcondition(cond_sell, title='Sell Alert', message="Sell Alert")
Upvotes: 0
Views: 904
Reputation: 1961
This is expected behavior if you calculate your script in scope of other timeframe. If you on a 60 min
chart, and setting your indicator time frame to 1D
, then you will be given just 1 value per session of your 60 min
chart.
This is the same as using security()
function. Info about this can be found here:
https://www.tradingview.com/pine-script-docs/en/v5/concepts/Other_timeframes_and_data.html#gaps
"Hidden" gaps
parameter (as you using security
function implicitly by using resolution
parameter) can be set in study()
function as resolution_gaps = false
:
So you need to rewrite your study call as:
study(StudyName, shorttitle=ShortStudyName, overlay=true, resolution="", resolution_gaps = false)
Upvotes: 1