Using Loops
Forums › ProRealTime English forum › ProOrder support › Using Loops
- This topic has 8 replies, 4 voices, and was last updated 5 years ago by
Vonasi.
-
-
04/29/2016 at 12:17 PM #6198
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.
04/29/2016 at 1:12 PM #6213Hello,
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.
04/30/2016 at 12:50 AM #6240Nicholas 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/
1234567891011Value = 0FOR 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]) THENValue = Value + 1 // take the previous value if the condition was met and add 1ELSEBREAK //we are exiting the 'FOR NEXT' loop here // When the above IF condition is not met break and start the Loop again.ENDIFNEXTRETURN Value4. 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 🙂
1 user thanked author for this post.
04/30/2016 at 8:37 AM #6242You 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/
12345678count = 0for i = 1 to xCandles doc1 = BBup[i]<UpperBand[i]c2 = BBdown[i]>LowerBand[i]if c1 and c2 thencount = count+1endifnextI 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. 🙂
07/19/2019 at 1:07 PM #102938Hi 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
07/19/2019 at 4:27 PM #10296007/20/2019 at 4:06 AM #102995Hi 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?
123456For f1 = 1 to 10z= MIN (g2-g1,z)If z<z[1] thenAnswer=f1EndifNextThanks,
Finning
07/20/2019 at 4:09 AM #10299607/20/2019 at 8:24 AM #103002Code 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!
-
AuthorPosts
Find exclusive trading pro-tools on