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.
Sorry, that should read, does not get reset to 0/ZERO again
JSParticipant
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).
JSParticipant
Senior
By the way, welcome to the forum… 😉
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.
JSParticipant
Senior
Why does it show false information?
When you don’t use “Continue”, your indicator correctly shows the two values (result and signal)…
Thankyou for the clarification JS