2

i´m trying to plot a fill between two moving averages in a 2 minutes chart to identify a trend of the chart, the first one is a 5 minutes time frame 50 periods length MA and the second one is a 2 minutes time frame 2 periods length MA.

When i try to add a fill betwwen the two plots, i have two options to plot the fill: 1.-Changing the chart time frame to 5 minutes to match with the highest time frame of the 50 periods MA, doing this i can see the fill correctly but i need stay in the 2 minutes chart time frame and 2.- Diasble the GAP option from the indicator config from the whole chart staying in the 2 minutes chart but the plots just become "not smoothed", so whats the propper way to stay in a 2 minutes chart and plot correctly the fill between the 2 MAs?

Here is my code

`

//@version=5
indicator("MA Fill", shorttitle="MA Fill", overlay=true, timeframe="", timeframe_gaps=false)

i2 = request.security(syminfo.tickerid, "5", ta.sma(close, 50))
ma2 = plot(i2, color = #ff9800)
ema2 = ta.sma(close, 2)
ema2plot = plot(ema2, color=color.new(color.black,100), style=plot.style_line, linewidth=1, title="EMA(2)", editable = false)
fill(ema2plot, ma2, color = ema2 > i2 ? color.new(#99ff0b, 85) : ema2 < i2 ? color.new(#ff3021, 85) : na, title = "Trend Fill")

` If i leave the Gaps option enabled, i don´t have the fill

If i uncheck the Gaps option i now have the fill but the wave looks "coarse and sharp"

If i move to the 5 min chart time frame, i have a fill and a smooth wave but i need stay in the 2 minutes time frame

Thank in advance.

I'm trying all above without success

vitruvius
  • 15,740
  • 3
  • 16
  • 26

2 Answers2

0

You cannot really do what you want to do.

The problem is, in order for fill() to work, your plots must have valid numbers.

When you have the gaps option enabled, the line looks "smooth" because you will only have a value on your chart whenever that value is available on the higher timeframe. So, if you are on the 1 min timeframe and requesting data from the 5 min timeframe, you will only have a valid value every five bars. And for the other bars, you will have na (hence the "gap"). Since you have na values, fill() does not work with this option.

Now, when you have the gaps option disabled, Tradingview will fill those gaps with the latest known value. This causes the line to be "not smooth".

vitruvius
  • 15,740
  • 3
  • 16
  • 26
0

You can use fillgaps=true when there's gaps in the data.

fill(ema2plot, ma2, color = ema2 > i2 ? color.new(#99ff0b, 85) : ema2 < i2 ? color.new(#ff3021, 85) : na, title = "Trend Fill", fillgaps=true)
Frik
  • 486
  • 6
  • 8