Re: [amibroker] nested FOR loop question

 

Thanks for the feedback.  I got a response back from amibroker.
He suggested I use an IIf within the function I was interested in.

I love simplicity - when it works.  Here's the new code.

myHHVMACD    = HHV(IIf(u1 == 1, var1, -999999), 99999);

By setting the values as shown, I could get the HHV function to
give me what I want based on the 'condition' of simple u1 == 1.

Thank you,

Karl

On Wed, Apr 6, 2016 at 2:13 AM, Howard B howardbandy@gmail.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Hi Karl --

Here is a link to the AmiBroker Reference for the For statement:
https://www.amibroker.com/guide/keyword/for.html

For loops can be nested.  Be careful to avoid confusion between the index variables controlling each loop.  But you can refer to the value of the index of the outer loop when setting the range of the inner loop, which seems to be what you are asking.

for( i = 1; i < BarCount; i++ )
{
    for( j = i; j < myCount; j++ )

    {
        //  your comparison
    }

}

Best,
Howard

On Fri, Apr 1, 2016 at 9:12 PM, karl.bergerson@gmail.com [amibroker] <amibroker@yahoogroups.com> wrote:
 

Can I use a nested FOR loop or .. to perform
an operation such as HHV on a subset of records
from a larger set of records where the subset is
chosen based on meeting a certain condition?

EXAMPLE:
I want to do the HHV of column 3 on 4 records
within the last 7 records where column 4 value
is 1.  Column 2 is a flag for me.  The number
of records to consider (4) is set by user.

I need the loop to keep reading and calculating
the values until 4 records have been found that
meet the condition and then perform the operation
such as HHV.

I seem unable to figure out how to write this code.
Any help would be Much appreciated!!

col 1 col 2 col 3   col 4

date1 close1 value1 1
date2 close2 value2 0
date3 close3 value3 0
date4 close4 value4 1
date5 close5 value5 1
date6 close6 value6 0
date7 close7 value  1

I want the HHV of records from date1, date4,
date5 and date7.







--
Karl Bergerson (カール バーガーソン)

〒002-0857
 札幌市北区屯田7条11丁目10-10
電話 050-5809-7325 (Skype)

__._,_.___

Posted by: Karl Bergerson <karl.bergerson@gmail.com>
Reply via web post Reply to sender Reply to group Start a New Topic Messages in this topic (3)

Have you tried the highest rated email app?
With 4.5 stars in iTunes, the Yahoo Mail app is the highest rated email app on the market. What are you waiting for? The Yahoo Mail app is fast, beautiful and intuitive. Try it today!

**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.

TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com

TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)

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


.

__,_._,___


EmoticonEmoticon