Infinite Loop – While in If function
Forums › ProRealTime English forum › ProBuilder support › Infinite Loop – While in If function
- This topic has 8 replies, 3 voices, and was last updated 5 years ago by vetrader.
-
-
04/10/2019 at 7:17 AM #95901
I have a problem to find a solution for an infinite loop problem. The code below works fine, but with a while command in the if function, I receive the infinite loop message. The code should do the following:
- The if function is the trigger to set pb = 1 and calculate krange/kprice/kbuy
- Now pb should remain at 1 and krange/kprice/kbuy should be calculated on every new bar UNTIL close < lowerband
- I supposed after the if line: while close < lowerband do
Any idea?
12345678if dir = 1 and count <= maxbars and count >= minbars and close < upperband thenpb = 1krange = upperband-lowerbandkprice = lowerband-closekbuy = abs(kprice/krange)*100elsepb= 0endif04/11/2019 at 8:40 AM #96025I don’t know the entire code, so it is difficult to make a precise answer, but I think that there should be another way to make the calculation avoiding the while/wend loop. I do not see any count variable increasing?
Why not just using: if close<lowerband then .. endif ?
04/11/2019 at 11:18 AM #96052Count simply counts bars outside of a band in relation to a defined bar range – this works fine. The if function is now the trigger for the first close below the upperband – works also fine – but only for one Bar. But now, if this trigger is 1 it should remain at 1 until close < lowerband or close > upperband…In other words: If the trigger is at 1, I want to screen until close is between upperband/lowerband and if close is outside of the bands trigger should 0. Do you know what I mean?
12345678910111213141516if dir = 1 thenpbuy = close[1] > upperband[1]count = 0while pullbuy[count] docount = count + 1wendendifif dir = 1 and count <= maxbars and count >= minbars and close < upperband thenpb = 1krange = upperband-lowerbandkprice = lowerband-closekbuy = abs(kprice/krange)*100elsepb= 0endif04/11/2019 at 12:44 PM #96070Not really sure of what you want to achieved, it is still part of a complete code and some variables are missing for a better understanding, but:
123while pullbuy[count] docount = count + 1wendit has no start and no end, that’s why you fell into an infinite loop.
BTW, is pullbuy the same variable as pbuy?04/11/2019 at 1:37 PM #96088Sorry…it’s only “pullbuy” – pullbuy/pbuy was a copy/paste error. BUT I don’t need a solution for the first if function – This works fine, like described above. I need a solution for the second if function – In this function pb is triggerd to 1 and should remain at 1 UNTIL close is within upperband/lowerband. I don’t have more code – consider upperband/lowerband just as Bollinger Bands.
12345678910111213141516171819minbars = 2maxbars = 10if dir = 1 thenpullbuy = close[1] > upperband[1]count = 0while pullbuy[count] docount = count + 1wendendifif dir = 1 and count <= maxbars and count >= minbars and close < upperband thenpb = 1krange = upperband-lowerbandkprice = lowerband-closekbuy = abs(kprice/krange)*100elsepb= 0endif04/11/2019 at 1:55 PM #96090Something like this perhaps. Not tested.
123456789101112131415161718192021222324minbars = 2maxbars = 10if dir = 1 thenpullbuy = close[1] > upperband[1]count = 0while pullbuy[count] docount = count + 1wendendifif count <= maxbars and count >= minbars and close < upperband thencountok = 1endifif dir = 1 and countok and close < upperband thenpb = 1krange = upperband-lowerbandkprice = lowerband-closekbuy = abs(kprice/krange)*100elsepb= 0countok = 0endif1 user thanked author for this post.
04/11/2019 at 2:27 PM #9610204/11/2019 at 2:39 PM #96104No problem – glad we finally worked out what it was that you wanted! Don’t forget that you can click ‘Thanks’ on any helpful replies.
On a separate note – did you spot that the indicator you requested elsewhere is now in the library:
I only ask because you have not replied to the topic.
1 user thanked author for this post.
04/11/2019 at 4:34 PM #96137 -
AuthorPosts