Using Loops

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #6198 quote
    David
    Participant
    Veteran

    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.

    #6213 quote
    Nicolas
    Keymaster
    Master

    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.

    #6240 quote
    David
    Participant
    Veteran

    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.

    1. I tried copying and pasting the examples in the links but  they didn’t work for me
    2. Can Loops be used in developing Automatic Trading systems (without calling the indicator)? I haven’t seen anyone use loops in their online postings.
    3. 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 🙂

    UkDownUnder thanked this post
    #6242 quote
    Nicolas
    Keymaster
    Master

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

    #102938 quote
    Finning
    Participant
    Veteran

    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

    #102960 quote
    Vonasi
    Moderator
    Master
    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.

    #102995 quote
    Finning
    Participant
    Veteran

    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

    #102996 quote
    Finning
    Participant
    Veteran

    Sorry!! Am on mobile and the code paste didn’t work properly!!!

    Am away from desktop for next couple of days.

    #103002 quote
    Vonasi
    Moderator
    Master

    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!

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.

Using Loops


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
David @dwgfx Participant
Summary

This topic contains 8 replies,
has 4 voices, and was last updated by Vonasi
6 years, 7 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/29/2016
Status: Active
Attachments: No files
Logo Logo
Loading...