Does anyone know what the maximum of IF’s are allowed within one strategy before it gets “confused”? And what is the max length of the code.
I wonder if I can put as many conditions in one strategy as I only require. And what would be you suggestion to make the code less cluttered as possible?
I have not yet run into issues with the number of If and even nested if statements used (or lines of code for that matter).
But I do experience issues when using 2 or more loops (however number of iterations could maybe also play a role).
WingParticipant
Veteran
I tried this one time and I believe the maximum amount of IF statements/actions per iteration is something like 1000-2000. As for maximum code length it is somewhere around 10000-20000 lines of code I believe. If you really want to know you can test it yourself.
Here you may want to find clues and hints on some improvements for screeners (and strategies as well): https://www.prorealcode.com/blog/learning/speed-calculation-indicator/
Too many nested IFs can lead to slower execution and, maybe, some interpretation issues. It is preferrable to use multiple conditions on the same line, example:
// instead of:
IF a THEN
IF b THEN
IF c THEN
.
.
.
ENDIF
ENDIF
ENDIF
// it is preferrable to write:
IF a AND b AND c THEN
.
.
.
ENDIF
…I think long before you have reached the point that PRT gets “confused” you will reach a point that backtesting your strategy is painfully slow.