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

RE: [amibroker] Re: loop counter



PureBytes Links

Trading Reference Links

Tomasz already answered this with the same solution, but my formatting was
off. For clarification, this is a corrected version (I hope):

 

//Count bars since flat or down, ergo # of consecutive up bars.

up = BarsSince(C <= Ref(C,-1)); 

//Count bars since flat or up, ergo # of consecutive down bars.

dn = BarsSince(C >= Ref(C,-1));

 

Plot(up,"up",colorGreen,styleHistogram);

Plot(dn,"dn",colorRed,styleHistogram);

--

Terry

 

-----Original Message-----
From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf
Of Terry
Sent: Thursday, January 11, 2007 09:01
To: amibroker@xxxxxxxxxxxxxxx
Subject: RE: [amibroker] Re: loop counter

 

No loop needed:

 

//Count bars since flat or down, ergo # of consecutive up bars.

up = BarsSince(C <= Ref(C,-1)); 

//Count bars since flat or up, ergo # of consecutive down bars.

dn = BarsSince(C >= Ref(C,-1));

 

Plot(up,"up",colorGreen,styleHistogram);

Plot(dn,"dn",colorRed,styleHistogram);

 

--

Terry

-----Original Message-----

From: amibroker@xxxxxxxxxxxxxxx [mailto:amibroker@xxxxxxxxxxxxxxx] On Behalf

Of klaus_korneker

Sent: Thursday, January 11, 2007 04:31

To: amibroker@xxxxxxxxxxxxxxx

Subject: [amibroker] Re: loop counter

 

Hi Nicolas,

 

thank you very much !!!

I thought i need a loop to do the job.

Really excellent.

 

 

 

 

--- In amibroker@xxxxxxxxxxxxxxx, "discuslorraine" <nicolas.navet@xxx>

wrote:

>

> Hello,

> 

> Here is a solution :

> 

> Cpt = 0;

> for ( i=1; i < BarCount; ++i ) {

>     if ( C[i] > C[i-1] ) ++Cpt;

>     else Cpt = 0;

>     Count[i] = Cpt;

> }

> 

> Plot(Count,"Count",colorRed);

> 

> Best regards, Nicolas

> 

> 

> --- In amibroker@xxxxxxxxxxxxxxx, "klaus_korneker"

> <klaus_korneker@> wrote:

> >

> > Hello,

> > 

> > i have tried that already, but it counts all bars (whole history)where

> > the condition is true. I want that it always resets to zero when the

> > condition isn't true and when it is true it should start again from

> > zero. Can you help please ?

> > 

> > 

> > 

> > 

> > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@> wrote:

> > >

> > > Hello,

> > > 

> > > This single-liner and does not require any looping:

> > > 

> > > Count = Cum( C > Ref( C, -1 ) );

> > > 

> > > 

> > > Best regards,

> > > Tomasz Janeczko

> > > amibroker.com

> > > ----- Original Message ----- 

> > > From: "klaus_korneker" <klaus_korneker@>

> > > To: <amibroker@xxxxxxxxxxxxxxx>

> > > Sent: Thursday, January 11, 2007 9:43 AM

> > > Subject: [amibroker] Re: loop counter

> > > 

> > > 

> > > > Hello,

> > > > 

> > > > thanks a lot !

> > > > 

> > > > Can you please also show me how i could count any condition like

> > > > C>ref(C,-1);

> > > > 

> > > > I would like to plot a graph that shows me the number of bars

where

> > > > the following condition is true. 

> > > > 

> > > > Thanks !

> > > > 

> > > > Klaus

> > > > 

> > > > 

> > > > --- In amibroker@xxxxxxxxxxxxxxx, "Tomasz Janeczko" <groups@>

wrote:

> > > >>

> > > >> Hello,

> > > >> 

> > > >> See Comments section in BarIndex() reference:

> > > >> 

> > > >> http://www.amibroker.com/guide/afl/afl_view.php?barindex

> > > >> 

> > > >> When running a loop over array you must NOT access

> > > >> elements outside 0..BarCount-1 range.

> > > >> 

> > > >> The code that you want to write should look as follows:

> > > >> 

> > > >> bi = BarIndex();

> > > >> 

> > > >> for( i = 0; i < BarCount; i++ )

> > > >> {

> > > >>  Cnt[ i ] = i + bi[ 0 ];

> > > >> }

> > > >> 

> > > >> Best regards,

> > > >> Tomasz Janeczko

> > > >> amibroker.com

> > > >> ----- Original Message ----- 

> > > >> From: "klaus_korneker" <klaus_korneker@>

> > > >> To: <amibroker@xxxxxxxxxxxxxxx>

> > > >> Sent: Wednesday, January 10, 2007 8:30 PM

> > > >> Subject: [amibroker] Re: loop counter

> > > >> 

> > > >> 

> > > >> > Thanks for the explanation. But how can i now create a

> > > >> > barindex(counter) through a loop. Graph1 plots the barindex.

> I have

> > > >> > tried to use (i = 0; i < LastValue(BarIndex()); i++ ) but this

> > > >> > generates an error.

> > > >> > Can you help ?

> > > >> > 

> > > >> > Cnt = 0;

> > > >> > for( i = 0; i < LastValue(BarIndex()); i++ )

> > > >> > {

> > > >> > Cnt[ i ] = i ;

> > > >> > }

> > > >> > 

> > > >> > Graph0 = Cnt;

> > > >> > Graph1 = BarIndex();

> > > >> > 

> > > >> > 

> > > >> > --- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@> wrote:

> > > >> >>

> > > >> >> BarCount does not necessarily == LastValue(BarIndex())

> > > >> >> 

> > > >> >> This is because Amibroker uses "quickAFL" which means it

> only uses

> > > >> > enough

> > > >> >> bars to "get the job done". This frequently is not all the

bars.

> > > >> >> 

> > > >> >> --

> > > >> >> Terry

> > > >> >> 

> > > >> >> -----Original Message-----

> > > >> >> From: amibroker@xxxxxxxxxxxxxxx

> [mailto:amibroker@xxxxxxxxxxxxxxx]

> > > >> > On Behalf

> > > >> >> Of klaus_korneker

> > > >> >> Sent: Wednesday, January 10, 2007 09:48

> > > >> >> To: amibroker@xxxxxxxxxxxxxxx

> > > >> >> Subject: [amibroker] Re: loop counter

> > > >> >> 

> > > >> >> Hi Terry,

> > > >> >> 

> > > >> >> thank you very much for your explanation !

> > > >> >> However it looks a little bit strange. It works still the

same.

> > > >> >> When set the entire array to 0 with Cnt = 0; and click

Apply, it

> > > > shows

> > > >> >> the same value as with the confirmation code in the graph.

> > However 

> > > >> >> automatically after about 1 second it changes the value to 199

> > > > instead

> > > >> >> 4517

> > > >> >> 

> > > >> >> BTW: i know that it displays the number in the title based

on my

> > > >> > cursor. 

> > > >> >> 

> > > >> >> Regards

> > > >> >> 

> > > >> >> Klaus

> > > >> >> 

> > > >> >> 

> > > >> >> --- In amibroker@xxxxxxxxxxxxxxx, "Terry" <MagicTH@> wrote:

> > > >> >> >

> > > >> >> > To initialize the loop you should do this:

> > > >> >> > Cnt = 0; //Initializes entire array, not just 1st element.

> > > >> >> > 

> > > >> >> > When you click on the chart the number should change because

> > > > you are

> > > >> >> > selecting "that bar". Also see last paragraph about

barcount.

> > > >> > Otherwise,

> > > >> >> > your loop is correct.

> > > >> >> > 

> > > >> >> > Here's some code to verify with:

> > > >> >> > 

> > > >> >> > x = BarIndex();

> > > >> >> > Plot(x,"x",1,styleStaircase);

> > > >> >> > NumToStr(BarCount,1.0);

> > > >> >> > NumToStr(LastValue(BarIndex()),1.0);

> > > >> >> > 

> > > >> >> > Note the last two statements print in the interpretation

> > window and

> > > >> >> they are

> > > >> >> > different because of quickAFL. The first changes with your

> > > > selection

> > > >> >> and the

> > > >> >> > number of bars showing. The last does not change. It is the

> > > > absolute

> > > >> >> number

> > > >> >> > of bars in your data. This is probably the reason your

> > results are

> > > >> >> changing

> > > >> >> > in unexpected ways as you are using BarCount.

> > > >> >> > --

> > > >> >> > Terry

> > > >> >> > 

> > > >> >> > -----Original Message-----

> > > >> >> > From: amibroker@xxxxxxxxxxxxxxx

> > [mailto:amibroker@xxxxxxxxxxxxxxx]

> > > >> >> On Behalf

> > > >> >> > Of klaus_korneker

> > > >> >> > Sent: Wednesday, January 10, 2007 07:43

> > > >> >> > To: amibroker@xxxxxxxxxxxxxxx

> > > >> >> > Subject: [amibroker] loop counter

> > > >> >> > 

> > > >> >> > Hello,

> > > >> >> > 

> > > >> >> > i am trying to build a counter with a loop. i have already

> > > > tried the

> > > >> >> > following, but it seems that anything is wrong. The chart

> > shows the

> > > >> >> > bar number, but when i click inside the chart, the number

> > changes.

> > > >> >> > 

> > > >> >> > Cnt[0] = 0;

> > > >> >> > for( i = 0; i < BarCount; i++ )

> > > >> >> > { 

> > > >> >> >     Cnt[ i ] = i ;

> > > >> >> > } 

> > > >> >> > 

> > > >> >> > Graph0 = Cnt;

> > > >> >> > 

> > > >> >> > Thanks i advance !

> > > >> >> > 

> > > >> >> > 

> > > >> >> > 

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

> > > >> >> >

> > > >> >> 

> > > >> >> 

> > > >> >> 

> > > >> >> 

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

> > > >> >>

> > > >> > 

> > > >> > 

> > > >> > 

> > > >> > 

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

> > > >> > 

> > > >> > 

> > > >> > 

> > > >> > 

> > > >> >

> > > >>

> > > > 

> > > > 

> > > > 

> > > > 

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

> > > > 

> > > > 

> > > > 

> > > > 

> > > >

> > >

> >

>

 

 

 

 

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

 

 

 

 

 

 

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

 

    http://groups.yahoo.com/group/amibroker/

 

    Individual Email | Traditional

 

    http://groups.yahoo.com/group/amibroker/join

    (Yahoo! ID required)

 

    mailto:amibroker-digest@xxxxxxxxxxxxxxx 

    mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx

 

    amibroker-unsubscribe@xxxxxxxxxxxxxxx

 

    http://docs.yahoo.com/info/terms/

 


Content-Description: "AVG certification"
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.9/622 - Release Date: 1/10/2007 2:52 PM