How to code UNTIL?
Forums › ProRealTime English forum › ProOrder support › How to code UNTIL?
- This topic has 3 replies, 2 voices, and was last updated 6 years ago by
robertogozzi.
-
-
11/19/2019 at 4:44 AM #113082
Hi
I’m trying to code UNTIL using the below example. I used IF, WHILE and BREAK but an infinite loop was detected and stopped the backtest. Help please to correct my code.
If my long trade closes early due to a stop loss, then I don’t want the system to enter into another long trade while x is still greater than y UNTIL y > x i.e. exit long position condition is met which should reset a back to zero.
I have tried to code a = 1 whilst x is still greater than y when my long trade closes early due to a stop loss.
12345678910111213141516171819202122232425x = AroonUp[10]y = AroonDown[10]a = 0IF PositionPerf(1) < 0 AND TRADEPRICE(1) < TRADEPRICE(2) THENWHILE (x > y)a = 1IF (y > x) THENBREAKENDIFWENDENDIF// Conditions to enter long positions//IF a = 0 AND (x > y) AND (x > 70) THENBUY 1 PERPOINT AT MARKETENDIF// Conditions to exit long positions//IF (y > x) THENSELL AT MARKETENDIFThanks
Sachin
11/19/2019 at 8:25 AM #113084It’s an infinite loop, in between WHILE ….WEND initial conditions never change.
Indeed there’s no need for an iteration, another IF…ENDIF will do.
Replace lines 7-12 with:
123If x > y thena = 1ENDIF2 users thanked author for this post.
11/19/2019 at 6:25 PM #113144Thanks Roberto
However, wouldn’t the suggested code change prevent the next long trade even after y becomes greater than x if there is no other trade executed after the stop loss exit trade?
11/19/2019 at 6:42 PM #113147You’ll have to assign a different value to a when it’s time to, not always.
Replace line 4 with:
1ONCE a = 0Then you’ll need to add:
1a = 0somewhere in the code to reenable trading when you want to, according to your conditions.
-
AuthorPosts
