如何在 pine 编辑器的 "if" 函数中使变量为真或假?

How to make a variable true or false in the "if" function in pine editor?

我在tradingview交易策略时遇到的一个很大的问题就是无法将两种策略结合起来。例如,每当布林带中的价格上涨时,我都需要一个变量为真,以便我将来可以使用它。如果有人知道这个问题的解决方案,我将很乐意利用他的经验。

if crossover(x > y)
    test = true
if test
    strategy.entry("Short", strategy.short, oca_type=strategy.oca.cancel, comment="Short")

您必须首先创建一个可变变量并在全局范围内对其进行初始化: 请注意,crossover 函数接受以逗号分隔的参数。

var bool test = false
if crossover(x, y)
    test := true
if test
    ...

bool test = crossover(x, y) ? true : false
if test
    ...