从系列中获取恒定值 [英] Getting a constant value from a series
问题描述
我想为变量分配一个常量值.这个值来自一个系列.该值是 10 根柱线,除非有新柱线,否则必须保持不变.
我尝试了这段代码并对其进行了许多变体,但没有奏效.
//@version=4研究(标题=X",覆盖=假)无功x = 0.0x := valuewhen(barstate.islast, sum(cht_acum[10], 10), 1)情节(x,标题=X")
我没有得到一条直线,或者我得到了 NA.如何解决问题?
Version 1
很难弄清楚你想要什么.这可能会接近.您可以使用输入仅在最后一个条形图上绘制:
//@version=4研究(标题 = X",叠加 = 假)cht_acum = 关闭plotOnLastBarOnly = 输入(假)x = sum(cht_acum[10], 10)情节(barstate.islast 或不 plotOnLastBarOnly ?x:na,标题 = X")
版本 2
此版本使用了
I want to assign a constant value to a variable. This value comes from a series. The value is 10 bars back, and must stay constant unless there is a new bar.
I tried this code and lots of variations on it, but it didn't work.
//@version=4
study(title = "X", overlay = false)
var x = 0.0
x := valuewhen(barstate.islast, sum(cht_acum[10], 10), 1)
plot(x, title = "X")
I don't get a straight line, or I get NA. How to resolve the issue?
Version 1
Hard to figure out what you want. This may come close. You can use the Inputs to plot only on the last bar:
//@version=4
study(title = "X", overlay = false)
cht_acum = close
plotOnLastBarOnly = input(false)
x = sum(cht_acum[10], 10)
plot(barstate.islast or not plotOnLastBarOnly ? x : na, title = "X")
Version 2
This version uses the brilliant Sum()
function from alexgrover found in Functions Allowing Series As Length - PineCoders FAQ, which accepts a series length. Should be closer to your needs:
//@version=4
study("")
Sum(src,p) => a = cum(src), a - a[max(p,0)]
cond = rising(close, 30)
sourceSeries = 1.
var count = 0.
if cond
count := 1.
else
count := min(10, count + 1)
total = Sum(sourceSeries, count)
plot(total)
plotchar(cond, "cond", "•", location.top, size = size.tiny)
这篇关于从系列中获取恒定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!