如何添加全部或部分条件以提醒? - 松脚本交易视图
How to add all or some conditions to alert ? - Pine script tradingview
我有蜡烛的条件列表。这只是一个例子:
aa = (close > open) and (low > low[1])
bb = (close[1] > open[1]) and (close[1] > 5)
cc = (close > ((high[1] - low[1])*23.6/100 + low[1]))
dd = (close > EMA34) and (close > ema(close, 10))
我使用以下代码设置提醒:
if aa
alert("A- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if bb
alert("B- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if cc
alert("C- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if dd
alert("D- " + tostring(close, "#.######"), alert.freq_once_per_bar)
对于每个条件,我都会在消息的开头收到一个带有字母的警报,这样我就可以知道条件的优先级,即 A 是最好的,D 是最后一个。
我想知道有没有办法同时检查所有条件,所以我可以设置优先级:
- 如果警报满足所有条件,那么它是最好的 A
- 如果警报至少满足 3 个条件,则为 B
- 如果警报至少有 2 个条件,则为 C
- 如果只满足1个条件,则为D
真实列表有10多个条件,我无法手动检查它们。请给我一些代码以编程方式进行。
我想,这和数组有关,但我不知道该怎么做。
谢谢你帮助我。
aa = (close > open) and (low > low[1]) ?1:0
bb = (close[1] > open[1]) and (close[1] > 5) ?1:0
cc = (close > ((high[1] - low[1])*23.6/100 + low[1])) ?1:0
dd = (close > EMA34) and (close > ema(close, 10)) ?1:0
number_of_condition_true=aa+bb+cc+dd
bool all_condition_true=na
bool three_condition_true=na
bool two_condition_true=na
bool one_condition_true=na
bool none_condition_true=na
if number_of_condition_true>=4
all_condition_true:=true
else if number_of_condition_true>=3
three_condition_true:=true
else if number_of_condition_true>=2
two_condition_true:=true
else if number_of_condition_true>=1
one_condition_true:=true
else if number_of_condition_true==0
none_condition_true:=true
这是其中一种方法,此代码将帮助您编写逻辑程序。在上面的代码中,如果为真,我将其替换为数值,而不是我添加了所有,这将为您提供一次整体的真实情况。
我有蜡烛的条件列表。这只是一个例子:
aa = (close > open) and (low > low[1])
bb = (close[1] > open[1]) and (close[1] > 5)
cc = (close > ((high[1] - low[1])*23.6/100 + low[1]))
dd = (close > EMA34) and (close > ema(close, 10))
我使用以下代码设置提醒:
if aa
alert("A- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if bb
alert("B- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if cc
alert("C- " + tostring(close, "#.######"), alert.freq_once_per_bar)
else if dd
alert("D- " + tostring(close, "#.######"), alert.freq_once_per_bar)
对于每个条件,我都会在消息的开头收到一个带有字母的警报,这样我就可以知道条件的优先级,即 A 是最好的,D 是最后一个。
我想知道有没有办法同时检查所有条件,所以我可以设置优先级:
- 如果警报满足所有条件,那么它是最好的 A
- 如果警报至少满足 3 个条件,则为 B
- 如果警报至少有 2 个条件,则为 C
- 如果只满足1个条件,则为D
真实列表有10多个条件,我无法手动检查它们。请给我一些代码以编程方式进行。
我想,这和数组有关,但我不知道该怎么做。
谢谢你帮助我。
aa = (close > open) and (low > low[1]) ?1:0
bb = (close[1] > open[1]) and (close[1] > 5) ?1:0
cc = (close > ((high[1] - low[1])*23.6/100 + low[1])) ?1:0
dd = (close > EMA34) and (close > ema(close, 10)) ?1:0
number_of_condition_true=aa+bb+cc+dd
bool all_condition_true=na
bool three_condition_true=na
bool two_condition_true=na
bool one_condition_true=na
bool none_condition_true=na
if number_of_condition_true>=4
all_condition_true:=true
else if number_of_condition_true>=3
three_condition_true:=true
else if number_of_condition_true>=2
two_condition_true:=true
else if number_of_condition_true>=1
one_condition_true:=true
else if number_of_condition_true==0
none_condition_true:=true
这是其中一种方法,此代码将帮助您编写逻辑程序。在上面的代码中,如果为真,我将其替换为数值,而不是我添加了所有,这将为您提供一次整体的真实情况。