Working Through ‘Advanced Promgramming’, question. Loops
Forums › ProRealTime English forum › ProBuilder support › Working Through ‘Advanced Promgramming’, question. Loops
- This topic has 6 replies, 2 voices, and was last updated 8 hours ago by
meoldchina.
-
-
08/09/2025 at 2:36 PM #249555
Hi, new to the forums, new to ProRealTime programming. First off, having some C coding experience the concept of the code iterating through each bar automatically is a concept I need to get used too. In C/C++ you would need to code that element too.
I am working through Advanced programming > Loops > Descending loops and got to the code
Descending Loop123456789101112131415161718192021222324ema20=average[20,1]ema50=average[50,1]result=0FOR x = 100 DOWNTO 0 DOresult = result+(ema20[x]>ema50[x])IF result = 50 THENBREAKENDIFIF result < 30 THENCONTINUEENDIFIF result = 30 thensignal = 30ELSEsignal = 0ENDIFNEXTreturn result, (ema20>ema50), signalMy question (probably the first of many) is that as noted in the ‘IF result = 30 THEN signal = 30’ test, once ‘signal’ is equal to 30 it gets set at 30. However the true value of ‘signal’ is 30 or below and does not get reset to 30 again until ‘signal’ moves above 30. Isn’t his poor programming? Shouldn’t ‘signal’ get reset to zero just after the last ENDIF and before NEXT. I realise that this is just a teaching exercise but want to make sure I understand this correctly. Or is it simply dependant on exactly what you are trying to achieve? Thank you for your time.
08/09/2025 at 3:05 PM #249556Sorry, that should read, does not get reset to 0/ZERO again
08/10/2025 at 12:18 AM #249565Hi,
In this case, “signal” is not reset due to the use of the “CONTINUE” instruction…This ensures that when “result < 30”, the current iteration is skipped and execution continues with the next iteration…
Therefore, “CONTINUE” ensures that “signal” is not reset (because the code below the “CONTINUE” statement is not executed).
08/10/2025 at 12:29 AM #24956608/10/2025 at 10:40 AM #249575Thank you for that JS. I guess what I am trying to say is aren’t we getting false information? We do in fact have values of 30 or less (hypothetically they could in reality be 5, 10 ,20) but looking at the signals on the indicator they are all showing 30. So the indicator is surely showing incorrect information? In the previous code without, the CONTINUE instruction, we only generate two signals at 30, which is surely correct. That is why I thought ‘signal’ should get reset to zero just after the last ENDIF and before NEXT.
08/10/2025 at 10:58 AM #24957608/11/2025 at 8:16 PM #249640Thankyou for the clarification JS
1 user thanked author for this post.
-
AuthorPosts