【问题标题】:Pine script conditions / conditional-statements松树脚本条件/条件语句
【发布时间】:2021-12-05 19:14:37
【问题描述】:

我有6个条件:

c1 = ...
c2 = ...

然后,如果其中 4 个被填满(产生 15 个组合),我将执行一些命令。如何做到这一点?

例如:

cb1 = c1 and c2 and c3 and c4
cb2 = c1 and c2 and c3 and c5
cb3 = c1 and c2 and c3 and c6
cb4 = c1 and c2 and c4 and c5
cb5 = c1 and c2 and c4 and c6
cb6 = c1 and c2 and c5 and c6
cb7 = c1 and c3 and c4 and c5
cb8 = c1 and c3 and c4 and c6
cb9 = c1 and c3 and c5 and c6
cb10 = c1 and c4 and c5 and c6
cb11 = c2 and c3 and c4 and c5
cb12 = c2 and c3 and c4 and c6
cb13 = c2 and c3 and c5 and c6
cb14 = c2 and c4 and c5 and c6
cb15 = c3 and c4 and c5 and c6

// Set up alert
alertcondition(condition=cb1 or cb2 or cb3 or cb4 or cb5 or cb6 or cb7 or cb8 or cb9 or cb10 or cb11 or cb12 or cb13 or cb14 or cb15,
     message="cb")

【问题讨论】:

    标签: if-statement conditional-statements pine-script


    【解决方案1】:

    您可以阅读this 了解一些信息。

    if (condition1 == true) and (condition2 == true) and (condition3 == true) and (condition4 == true)
        // Do something
    else if (condition2 == true) and (condition3 == true) and (condition4 == true) and (condition5 == true)
        // Do something else
    

    请注意缩进。

    【讨论】:

    • 对于 6 例中的 4 例,剩下 16 种不同的组合。在 6 个案例中有 5 个不同的组合几乎爆炸了......是否有一个优雅的(即更紧凑的)配方代替?例如选择某个子集需要满足某些条件的数组或集合?
    【解决方案2】:

    我们可以做积分系统吗?例子

    condition1 is ok X=1
    condition2 is ok X=x+1
    condition3 is ok X=x+3
    condition4 is ok X=x+4
    
    if x>0
    do this
    else if x>1
    do this
    else if x>2
    do this    
    ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2023-01-13
      • 1970-01-01
      • 2016-06-25
      • 2013-03-09
      • 2011-05-29
      相关资源
      最近更新 更多