Hello,

It was explained many times on the list and it is documented in
http://www.amibroker.com/kb/2008/07/03/quickafl/
(take a close look at the picture)

that BarCount IS DYNAMIC, DEPENDENT on ZOOM.

The code here:

Plot( IIf( BarIndex()>= BarCount - EMABarsVisible21, EMA( C,21), Null ), "", 
colorViolet,styleNoLabel |5 );

is totally WRONG.

because it assumes that BarCount has any relationship with BarIndex().
IT DOES NOT!

The code will work only if ALL bars existing are in fact used by the 
formula.
It is NOT the case in majority of cases.

Only when you request all bars, or if you zoom out completely or if you 
press "refresh all" for the very first
time it will use all bars.
Otherwise the formula use LESS BARS than all and quoted formula is 
INCORRECT for all those cases.

Again, reading it:
http://www.amibroker.com/kb/2008/07/03/quickafl/
is necessary.

Short advice:
DO NOT use BarCount for ANYTHING else than building a for loop that 
iterates through array elements like
this:
for( i = 0 ; i < BarCount; i++ )
{
   array[ i ] = H[ i ] + L[ i ];
}

This is one and the only one use of BarCount (at least for people 
without proper understanding of what was described in the
article pointed out above).


Best regards,
Tomasz Janeczko
amibroker.com

On 2010-04-24 10:25, progster01 wrote:
> The working two-liner is great, and very clear to understand as given:
>
> bi = BarIndex();
> Plot( IIf( bi<  LastValue( bi ) - 21, Null, EMA( C, 21 ) ), "EMA", colorRed );
>
> But why doesn't this other code that was discussed:
>
> Plot( IIf( BarIndex()>= BarCount - EMABarsVisible21, EMA( C,21), Null ), "", 
> colorViolet,styleNoLabel |5 );
>
> successfully accomplish the same thing?
>
> Understanding the difference, exactly, is much to be desired, IMO.  Knowing 
> the platform deeply enough to understand and avoid such pitfalls is the goal 
> of many of us.
>
> I ask here on the list so that all may benefit from any answer that might be 
> provided.
>
>
> --- In [email protected], Tomasz Janeczko<gro...@...>  wrote:
>
>    
>> Original question was:
>>   >  How to plot 21 days EMA only for the last 21 bars.
>>
>> And the answer is TWO liner:
>>
>> |bi = BarIndex();
>> Plot( IIf( bi<  LastValue( bi ) - 21, *Null*, EMA( *C*, 21 ) ), "EMA",
>> *colorRed* );|
>>
>> And it works in ALL AmiBroker versions.
>>      
>
>
>
> ------------------------------------
>
> **** 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/
>
> Yahoo! Groups Links
>
>
>
>
>    

Reply via email to