Working Through ‘Advanced Promgramming’, question. Loops

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #249555 quote
    meoldchina
    Participant
    New

    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

    
    ema20=average[20,1]
    ema50=average[50,1]
    result=0
    
    FOR x = 100 DOWNTO 0 DO
    result = result+(ema20[x]>ema50[x])
    
    IF result = 50 THEN
     BREAK
    ENDIF
    
    IF result < 30 THEN
     CONTINUE
     ENDIF
    
    IF result = 30 then
     signal = 30
    ELSE
     signal = 0
    ENDIF
    
    NEXT
    
    return result, (ema20>ema50), signal
    

    My 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.

    #249556 quote
    meoldchina
    Participant
    New

    Sorry, that should read, does not get reset to 0/ZERO again

    #249565 quote
    JS
    Participant
    Senior

    Hi,


    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).

    #249566 quote
    JS
    Participant
    Senior

    By the way, welcome to the forum… 😉

    #249575 quote
    meoldchina
    Participant
    New
    Thank 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.
    #249576 quote
    JS
    Participant
    Senior
    Why does it show false information? When you don’t use “Continue”, your indicator correctly shows the two values (result and signal)…
    #249640 quote
    meoldchina
    Participant
    New
    Thankyou for the clarification JS
    JS thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Working Through ‘Advanced Promgramming’, question. Loops


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
meoldchina @meoldchina Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by meoldchina
5 months, 4 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 08/09/2025
Status: Active
Attachments: 2 files
Logo Logo
Loading...