我正在研究移动平均指标,该指标显示给定时间范围的MA线。 由于某种原因,MA线仅在最后一个ticker.id时段结束之前才移位。因此,例如,当我将指标设置为显示每日MA时,该行仅在当天关闭时更新。
(链接到图像https://i.stack.imgur.com/QjkvO.jpg)
有人知道我的指标将如何包含每日休市之间的数据,因此该行会不断更新吗?
我认为这条线没有被连续更新,也会导致应该在图表上1点/美元高度处绘制的MA线处正确绘制标签。
我最近才开始编写代码,所以请问这是一个愚蠢的问题。我已经编写了这段代码,着眼于其他指标,并尝试将零件适配到我自己的
这是整个指标的代码。
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1, barmerge.gaps_on, barmerge.lookahead_on)
plot(sourceEmaSmooth1, style=plot.style_line, linewidth=2, title="25 period", color=#a21e7b)
plotchar((sourceEmaSmooth1 ? Label : barstate.islast and not barstate.isconfirmed) ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, editable=false)
答案 0 :(得分:0)
将barmerge.gaps_on
与security()
一起使用会创建孔,它们在图表的分辨率下显示为na
值,这就是为什么您的ma并不总是显示的原因。这在历史柱上并不明显,因为plot()
函数填充了从无间隙到无间隙的空间(如果您绘制的是圆而不是线,则可以看到它)。
将barmerge.lookahead_on
与security()
一起使用会在历史柱线上产生超前偏差。如果您不对要获取的值建立索引,这会很讨厌,如本出版物中有关如何正确使用security()
的说明:How to avoid repainting when using security()。
我向您添加了show_last = 1
标签绘图电话并修复了有条件的电话。因为它现在仅绘制标签的最后一次出现,所以我们不再需要担心条形码状态:
//@version=4
study(title="Custom Timeframe SMA", shorttitle="Custom TF MA", overlay=true)
res = input(title="MA Timeframe", type=input.resolution, defval="D",options=["60", "240", "D", "W"])
length1 = input(title="SMA Length", type=input.integer, defval=50)
Label=input(title="show Labels",defval=true)
sma1 = sma(close, length1)
sourceEmaSmooth1 = security(syminfo.tickerid, res, sma1)
plot(sourceEmaSmooth1, linewidth=2, title="25 period", color=#a21e7b)
plotchar(Label ? sourceEmaSmooth1 : na, location=location.absolute, text=" 50 SMA", textcolor=#a21e7b, offset=10, show_last = 1, editable=false)