[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[amibroker] Re: Looping - our previous discussion



PureBytes Links

Trading Reference Links

Bernard,

> 1. Is it correct to refer to the j loop as being "nested" in the i 
> loop? I'm wondering whether the j loop completes its internal loop 
> for the 15 or so bars and then re-enters the i loop at the end or 
> whether both i and j loops run the 15 or so times?

Yes, the j loop is nested inside the i loop.

> 2. "i<BarCount-waitperiod" ? can you explain how the code translates
> that please? I thought that would have meant you terminate once the
> current bar is less than the total number of bars less 15, whereas
> it seems to me an you terminate at 15.

That statement is really a continuation condition, not a termination
condition. It means the loop will continue to run as long as i is less
than BarCount-waitPeriod.

> 3. You mentioned when we previously discussed this issue that Setup 
> has a "1" wherever C < BBandBot. Is that why in other codes, 
> sometimes the values of an array are set to 0 before a loop (to 
> remove any previous arrays triggered)?

There are two main reasons variables are set to zero before a loop.
The first is to ensure it's initialised with something before it's
referenced. If you try to reference a variable that hasn't been
initialised (ie. set to some value already), you'll get an error message.

The second, which is much more complicated, has to do with the scope
of variables. A variable can only be referenced if it's defined (in
AFL that means first mentioned) in the same or higher scope. So to
reference a variable outside a loop or if statement, it must also be
defined outside that loop or if statement. If the first mention of the
variable is inside a loop, then you can't access it outside the loop.
It effectively becomes private to the loop. So setting it to zero
before entering the loop ensures that it has scope outside the loop
and can thus be referenced after the loop has finished.

Not sure if that makes sense, but variable scoping can get to be quite
a complicated issue.

Regards,
GP




Please note that this group is for discussion between users only.

To get support from AmiBroker please send an e-mail directly to 
SUPPORT {at} amibroker.com

For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/

For other support material please check also:
http://www.amibroker.com/support.html
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/amibroker/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/amibroker/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:amibroker-digest@xxxxxxxxxxxxxxx 
    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    amibroker-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/