I have a list of conditions for a candle. This is just an example:
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))
I set alert using the following code:
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)
With each condition, I will get an alert with a letter at the beginning of the message so I can know the priority of the conditions, ie A is the best, D is the last one.
I would like to know if there is any way to check all conditions at the same time, so I can set the priority like:
The real list has more than 10 conditions so I cannot check them manually. Please give me some code to do it programmatically.
I think, it's something related to array but I don't know how to do it.
Thank you for helping me.
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
this is one of the ways ,this code will help you in programming your logic. in the above code i have replaced it into numerical value if true , than i have added all , this will give you the overall how may are true at a time.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.