简体   繁体   中英

Pine script conditions / conditional-statements

I have 6 conditions:

c1 = ...
c2 = ...

Then if 4 of them are fullfilled (yielding 15 combinations), I will execute some command. How to do this?

Eg:

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")

You can read this for some information.

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

Please note the indentation.

Could we do the point system? example

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    
...

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM