0

我如何将变量保存在 IF condation 中并稍后显示?

变量在 IF 条件外显示 0

我想显示 v1 和 v2

点击显示图片

//@version=4
study("Test2", shorttitle = "Test2", overlay=true)

v1 = 0.0
v2 = 0.0


r = high - low
large_candle = rising(r,50)

if large_candle
    v1 := high
    v2 := low
    target = "high = " + tostring(v1) + "\n low = " + tostring(v2)
//  label.new(bar_index, high, target, yloc = yloc.abovebar, color = color.red, style = label.style_arrowdown)

if (high-open) > 0.7 * (high-low) and open > close
    target = "Target 1 = " + tostring(v1) + "\n Target 2 = " + tostring(v2)
    label.new(bar_index, high, target, yloc = yloc.abovebar, color = color.black, style = label.style_arrowdown)

barcolor( large_candle ? color.yellow : na)

注意:我真的需要将这些变量保存为另一个代码(我将此代码编码为简单)。任何想法 ?

4

1 回答 1

0

我觉得这是做这项工作

如果有更好的答案会很好:)

//@version=4
study("Test2", shorttitle = "Test2", overlay=true)

v1 = 0.0
v2 = 0.0
v1 := nz(v1[1])
v2 := nz(v2[1])


r = high - low
large_candle = rising(r,50)

if large_candle
    v1 := high
    v2 := low
    target = "high = " + tostring(v1) + "\n low = " + tostring(v2)
    label.new(bar_index, high, target, yloc = yloc.abovebar, color = color.red, style = label.style_arrowdown)

if (high-open) > 0.7 * (high-low) and open > close
    target = "Target 1 = " + tostring(v1) + "\n Target 2 = " + tostring(v2)
    label.new(bar_index, high, target, yloc = yloc.abovebar, color = color.black, style = label.style_arrowdown)

barcolor( large_candle ? color.yellow : na)
于 2020-07-07T00:26:36.877 回答