动态绘图在日内工作但不是每天

dynamic plotting working intraday but not dailly

我想根据我正在查看的时间范围绘制一些 sma,如果它是每天或盘中。

基本上,我使用安全函数绘制 20 分钟时间范围内的 sma。 v0、v1、v7 和 v8 是与 sma 函数一起使用的长度变量。 m0、m1、m7、m8是变量,包含绘图的浮点值。

我使用一种变通方法不绘制我不需要的 sma,将“1”值分配给长度变量,然后将“na”分配给浮点值。

它在日内运行完美,但在每日时间范围内,它总是绘制一个以“1”作为长度值而不是 v7 和 v8 值的 sma。我真的不明白为什么。有人可以帮忙吗?

//@version=4
study(title="test", overlay=true)

//values for plot
colore_blu = #0000ff
spessorelinea = input(defval=2, title="Spessore linee")

// is timeframe intraday?
intra = timeframe.isintraday

//if timeframe is intraday than assign the right value to varaibles, otherwise assign 1
v0 = intra ? 13 : 1
v1 = intra ? 26 : 1

//if timeframe is not intraday than assign the right value to variables, otherwise assign 1
v7 = intra ? 1 : 1664
v8 = intra ? 1 : 3328

//display values for length
plot(v0, color=color.blue)
plot(v1, color=color.aqua)
plot(v7, color= color.maroon)
plot(v8, color=color.black)

//if length variable is 1 then sma is not available
m0 = v0 == 1 ? na : security(syminfo.tickerid, "20", sma(close, v0))
m1 = v1 == 1 ? na : security(syminfo.tickerid, "20", sma(close, v1))
m7 = v7 == 1 ? na : security(syminfo.tickerid, "20", sma(close, v7))
m8 = v8 == 1 ? na : security(syminfo.tickerid, "20", sma(close, v8))

// just for test, if i put values instead of variables v7 and v8, plotting is correct
m7_test = security(syminfo.tickerid, "20", sma(close, 1664))
m8_test = security(syminfo.tickerid, "20", sma(close, 3328))

//plotting sma
plot(m0, title="T-3", color=colore_blu, linewidth=spessorelinea, style=plot.style_line)
plot(m1, title="T-2", color=color.aqua, linewidth=spessorelinea, style=plot.style_line)
plot(m7, title="T+4", color=color.maroon, linewidth=spessorelinea, style = plot.style_line)
plot(m8, title="T+5 annuale", color=color.black, linewidth=spessorelinea, style = plot.style_line)
plot(m7_test, title="T+4", color=color.maroon, linewidth=spessorelinea, style = plot.style_cross)
plot(m8_test, title="T+5 annuale", color=color.black, linewidth=spessorelinea, style = plot.style_cross)

我不太确定当您不在盘中分辨率时需要绘制什么。这会以>盘中分辨率绘制图表分辨率的 13 和 26 MA。

//@version=4
study(title="test", overlay=true)

//values for plot
colore_blu = #0000ff
spessorelinea = input(defval=2, title="Spessore linee")

// is timeframe intraday?
intra = timeframe.isintraday

m0 = security(syminfo.tickerid, "20", sma(close, 13))
m1 = security(syminfo.tickerid, "20", sma(close, 26))
m7 = sma(close, 13)
m8 = sma(close, 26)

//plotting sma
plot(intra ? m0 : na, title="T-3", color=colore_blu, linewidth=spessorelinea, style=plot.style_line)
plot(intra ? m1 : na, title="T-2", color=color.aqua, linewidth=spessorelinea, style=plot.style_line)
plot(not intra ? m7 : na, title="T+4", color=color.maroon, linewidth=spessorelinea, style = plot.style_line)
plot(not intra ? m8 : na, title="T+5 annuale", color=color.black, linewidth=spessorelinea, style = plot.style_line)