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 amibroker@yahoogroups.com, 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.


Reply via email to