In the manual it advises not to use Loops but I would appreciate if someone could share an example of when a Loop would be useful so I can expand my understanding on them for potential ProOrder AutoTrading. If someone has an example it would be very much appreciated.
Hello,
We can do loops for a lot of things. They are made to increment or decrement variables to search for informations.
There are some examples in our online documentation in this pages :
(basic example of adding the moving average of the “i” period to the “a” variable)
http://www.prorealcode.com/documentation/for/
(another basic example of a loop using While/Wend : while “i ” is different from 11 we keep incrementing its value of the “Count” variable too)
http://www.prorealcode.com/documentation/while/
Hope it would be helpful.
Nicholas thanks for the links but I’m still not sure how to completely implement the Loops or still have a practical example in use except for below for an indicator.
- I tried copying and pasting the examples in the links but they didn’t work for me
- Can Loops be used in developing Automatic Trading systems (without calling the indicator)? I haven’t seen anyone use loops in their online postings.
- Can Loops be used in developed Indicator Creation? Yes
I found this example in Break indicator that worked for me: http://www.prorealcode.com/documentation/category/instructions/
Value = 0
FOR i = 1 TO 20 DO
// If I change the "1 TO 20" "1 TO 3" then the maximum result will be 3
// If I change the "1 TO 20" "0 TO 3" then the maximum result will be 4. Note: I find setting it to "0 to X" provides the correct graphic representation because "1 to X" lags 1 period.
IF (Close[i] < Open[i]) THEN
Value = Value + 1 // take the previous value if the condition was met and add 1
ELSE
BREAK //we are exiting the 'FOR NEXT' loop here // When the above IF condition is not met break and start the Loop again.
ENDIF
NEXT
RETURN Value
4. Is there a way to change the display to Histogram instead of line chart? I found it, yes you apply the settings on the actual chart 🙂
You can use loops any where you want.
You’ll find an interesting example in my recent screener here :
http://www.prorealcode.com/prorealtime-market-screeners/intraday-volatility-explosion-screener/
count = 0
for i = 1 to xCandles do
c1 = BBup[i]<UpperBand[i]
c2 = BBdown[i]>LowerBand[i]
if c1 and c2 then
count = count+1
endif
next
I create a loop over the last xCandles to test the bollinger bands and the keltner bands states in the past datas. That’s at least a practical example of what we can do by using loops. Hope you’ll understand better here. 🙂
Hi there,
if i was using a loop with the MIN function, I would like to know on which number/loop value this MIN value is attained. (e.g.- the loop is set to run from values 1 to 10, and the MIN was reached on loop value #5).
I would like to be able to find the loop value that gave me the MIN answer.
Could anyone please help me with how to do this?
Thanks,
Finning
b = average[200](close[1])
for j = 1 to 10
a = average[200](close[j])
b = min(b,a)
if b = a then
c = j
endif
next
Something like this? c = the loop count where the lowest value was found.
Hi Vonasi, that looks along the lines of what I was trying to do.
A question I had-and it looks like you can from the example code you supplied-can you run more than 1 action/equation in the same loop?
I had a go at writing my own loop-in the code supplied below-will it do what I want and the z[1] reference the z in this loop -or will the z[1] reference the z value of the bar before?
For f1 = 1 to 10
z= MIN (g2-g1,z)
If z<z[1] then
Answer=f1
Endif
Next
Thanks,
Finning
Sorry!! Am on mobile and the code paste didn’t work properly!!!
Am away from desktop for next couple of days.
Code tidied up for you.
Yes you can do whatever you like within the loop as long as it avoids an infinitive loop situation.
Your code example does not use the value of f1 unless it is used to calculate g1 and g2 so it is difficult to know if it will work as you want without knowing what g1 and g2 are!