Hello,

Joris, PLEASE STOP. You are providing FALSE information!

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

is INCORRECT because BarCount DEPENDS ON ZOOM FACTOR !

Only code provided BY ME, i.e.

bi = BarIndex();
Plot( IIf( bi<  LastValue( bi ) - 21, Null, EMA( C, 21 ) ), "EMA", colorRed );


is correct one, because it does NOT depend on zoom factor.

Why BarCount is DYNAMIC is explained in the Knowledge Base:
http://www.amibroker.com/kb/2008/07/03/quickafl/

Also your loops as I said are INCORRECT TOO.
You don't have enough AFL knowledge to give advices to other people.

You need to read documentation carefully instead of making assumptions and/or your own interpretations
that are often completely wrong.


Best regards,
Tomasz Janeczko
amibroker.com

On 2010-04-24 14:36, Joris Schuller wrote:


1. That line he put in works; however if you really want 21 bars instead of 22 you have to replace < by < =.

There is another solution as well using SetBarsRequired (see 5. below)

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

Tomasz will tell you that the equation works, and that the loop doesn't do anything except for slowing you down. That is incorrect: Without the loop this equation in 5.2+ does plot _all _points instead of (21) (see below). In addition, after the Reset all, there is no performance degradation. I don't know why it works, only that it does. Verify it yourself: it is a 15 sec procedure. (I am not proposing this since there are better ways now)

3. The mal-aligned loop works for all 5.2 and up versions as well as for 5.3. As an aside, it has the added advantage that it displays not just the end values but the last values on the RHS of each Visible Range.

4.Plot(IIF(BarIndex() ..... does not work for 5.2 and up versions. It does work for 5.3 and its last precursor (5.296). I found that out yesterday since I don't use it (irreversible file format)

I did some additional testing and tried to get an idea what caused this behavior and found:

5. If you add SetBarsRequired(-2,-2); the code below works for all 5.2 and up versions

SetBarsRequired(-2,-2 ); //SetBarsRequired(sbrAll,sbrAll )

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

Now with respect to your question about cause:

6. a. Plot(IIF(BarIndex() ..... alone does not work for 5.2+ but does in 5.3

b.With SetBarsRequired Plot(IIF(BarIndex() ..... also works in 5.2 and up

This suggests that QuickAFL, what I believe is on until it is turned off by SetBarsRequired has something to do with it. I have a feeling that changes made in QuickAFL for 5.3 rendered use of SetBarsRequired in front of Plot( IIf( BarIndex ...unnecessary in 5.3. Also I have had a few times that the values changed when adding setBarsRequired, even though the code didn't seem to require it (loops,scripts,DLL's). So if I have any questions about the results, the first thing I do is adding SetBarsRequired and look at its impact.

*From:* [email protected] [mailto:[email protected]] *On Behalf Of *progster01
*Sent:* Saturday, April 24, 2010 3:25 AM
*To:* [email protected]
*Subject:* [amibroker] Re: Restricted Plot; Final test procedure; mainly a response to Mike and Tomasz


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] <mailto:amibroker%40yahoogroups.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