【问题标题】:How to show such that the indicator's current value is greater than previous indicator value?如何显示指标的当前值大于之前的指标值?
【发布时间】:2022-01-23 13:28:36
【问题描述】:

语言新手。 我想知道随机线是向上还是向下(大于或小于前一个蜡烛条的值)。就像最后一根蜡烛条的随机黄金值为 25,我希望它显示它是否为 25> in当前实时蜡烛条,是否重绘无关紧要。谢谢。

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    你好拱门,欢迎来到 Pine Script。这是一个脚本,如果当前随机值大于前一个值,则该脚本会更改线上的颜色。

    要获得您喜欢的随机时间戳:

    sto = ta.stoch(close, high, low, length)
    

    要获得以前的随机值,您可以这样做:

    sto[1]
    

    要改变线条的颜色,你可以这样写:

    stoColor = sto[0] > sto[1] ? color.green : color.red
    plot(sto, color=stoColor, linewidth=2)
    

    这称为“三元 if 语句”。所以如果sto[0] > sto[1] 为真,stoColor 变量将变为 color.green。如果声明为假,stoColor 将变为 color.red。

    完整脚本:

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
    // © CanYouCatchMe
    
    //@version=5
    indicator("My Script")
    length = input.int(title="Length", defval=10, minval=0, maxval=100)
    sto = ta.stoch(close, high, low, length)
    
    //sto[1] means value on one bar back
    //if current > last is true, then stoColor = color.green. Else stoColor = color.red
    stoColor = sto[0] > sto[1] ? color.green : color.red
    
    plot(sto, color=stoColor, linewidth=2)
    

    【讨论】:

    • 谢谢!不使用“Else”如何编码?我应该将结果“if sto[0] > stop[1]”变为假,随机值“if sto[0] = stop[1]”作为另一种颜色以及“if sto[0]
    • 你可以写这个stoColor = sto[0] > sto[1] ? color.green : sto[0] == sto[1] ? color.orange : color.red所以如果sto[0]和sto[1]相同,颜色变成橙色。
    • 非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-16
    • 2012-07-14
    • 2023-04-01
    • 2018-09-23
    相关资源
    最近更新 更多