【问题标题】:Can i save variable in IF condation in Pinescript?我可以在 Pine Script 的 IF 条件下保存变量吗?
【发布时间】:2020-07-07 00:03:30
【问题描述】:

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

变量在 IF 条件之外显示为 0

我想显示 v1 和 v2

Click to show the image

//@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)

注意:我真的需要将这些变量保存为另一个代码(我将这段代码编码为简单)。 有什么想法吗?

【问题讨论】:

    标签: pine-script candlestick-chart cryptocurrency forex candlesticks


    【解决方案1】:

    我认为这是完成工作

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

    //@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)
    

    【讨论】:

      猜你喜欢
      • 2022-10-25
      • 2019-11-15
      • 1970-01-01
      • 1970-01-01
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-06
      相关资源
      最近更新 更多