0

I couldn't find if the following pine script statement can be written in a similar way using Python.

numWhy = (dirTrade == 0) ? 102 : goodDirection ? -103 : 104

or that it should be replaced by much more statements like

if dirTrade == 0:
   numWhy = 102
elif goodDirection:
   numWhy = -103
else:
   numWhy = 104

I know that the longer version usually will be more readable (and thus preferable) but the short version becomes better readable if a lot of similar tests must be performed.

How can the short version be transformed from pine to Python maintaining a short notation?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
SoftwareTester
  • 1,048
  • 1
  • 10
  • 25
  • Thanks for the info. After reading and testing the alternatives I found another alternative based on tupels at https://book.pythontips.com/en/latest/ternary_operators.html (if_test_is_false, if_test_is_true)[test]. Adanvantage fast to learn. Disadvantage: takes more time to run – SoftwareTester Aug 05 '23 at 14:12
  • I compared several methods mentioned using two examples. being the easy "numWhy = (dirTrade = 0) ? 111 : 112" and the more complex "numWhy := (dirTrade == 0) ? 108 : (goodDirection ? (goodSide ? -109 : (predictCrossAlma ? 110 : numWhy)) : numWhy)" It can be helpful for others I think. Should I reopen the question to post the results of the comparison? – SoftwareTester Aug 05 '23 at 14:19

0 Answers0