dear joris,
just read your post at a glance.
(1) I got your N+1 bar point.
(2) regarding my code,yes it does not do as desired.
before actual trying I had posted that on perception that it shall work.
then, I used the following.
ATA=0;
for(i=0;i<BarCount;i++)
{
ATA+=C[i];
}
ATA/=BarCount;
ATA=Sum(Close,BarCount-1)/BarCount;
Plot(ATA,"ATA",colorBlack,styleLine);
(3) At present, I can say only this.
after meticulously reading your post and deciphering it completly by
heart,shall express my opinion.
best regards
--- On Thu, 4/1/10, Joris Schuller <[email protected]> wrote:
From: Joris Schuller <[email protected]>
Subject: RE: [amibroker] regarding cum function
To: [email protected]
Date: Thursday, April 1, 2010, 12:31 PM
I have added a few lines to make you understand better what the issues are in
the code below.
1. WRB or NRB, NR7 or NR4 all have nothing to do with it, only C does. The
impact of the first bar is removed at the (n+1) bar in case of a SMA of n.
Even if there is a large difference in C between the first and the second bar,
it simple doesn’t matter. It is immaterial at bar n+1. Furthermore, let’s
assume that bar 1 has value 1 and the following bars are >100. Would you even
want to include that bar for any decisionmaking? Of course not.
2. You should not plot sum(C,BarCount) , but sum(C,BarCount) /Barcount. However
this will not display any lines. In the top left corner the value for the most
right bar in the visible range is displayed (If it show {EMPTY} click on most
right bar. To display a line you have to plot:
//Plot(LastValue( AVGSum),"\nATA - LastValue("+BarCount+")",5,5); //This draws
a line for the last value of AVGSUM. This will show a horizontal line
3. Not true: Visualize what a MA is. The impact of the first bar, included or
not, is long gone (Move thru the data and look at the data results in the top
left corner).
In conclusion: Comparison of B, C, and D with E and F show that within a small
number of bars the accuracy is more than adequate and the results for all
practical purposes identical. In addition, use of C and D allows for a running
determination of the ATA. With E only the ATA at the most right bar is
determined and with F only the last value of the barcount is displayed.
Moreover, often the ATA at the more recent time periods is so far removed from
the actual data, that significant data compression occurs. It is often much
better not to plot but instead display the data in a price plot as shown in A.
This also facilitates comparison of the various data.
Title = EncodeColor(4)+ _DEFAULT_NAME()+"; "+EncodeColor(1) +
StrFormat("{{NAME}} - {{INTERVAL}} ; {{DATE}}; O=%g, H=%g, L=%g, C=%g (%.1f%%)
{{VALUES}}", O, H, L, C, SelectedValue( 10*ROC( C, 1 ) ) );
Perfixed=Param("Period Fixed",20,1,7000,1);
GetPerformanceCount er(True);
{PerVariableBarInde x=(BarIndex());}//Bar Index variable
elapsed=GetPerformanceCount er();
"Bar Index: Time in ms = " + elapsed;
GetPerformanceCount er(True);
{PerVariableCum= (Cum(1)-1);} //Cum variable
elapsed=GetPerformanceCount er();
"Cum: Time in ms = " + elapsed;
MAFixed=MA(C,Perfixed);
MABarIndex=MA(C,PerVariableBarInde x);
MACum=MA(C,PerVariableCum) ;
AVGSum=Sum(C,BarCount)/(BarCount);
//COMPARE THOSE FIVE PLOTS AND THE DATA RESULTS!
Plot(C,"AVGSum("+WriteVal(BarCount,1.0)+") = "+WriteVal(AvgSum,2.4)+";
C",1,64); // A
Plot(MAFixed,"\nMAFixed("+Perfixed+")",colorGreen,5);// B
Plot(MABarIndex,"\nMABarIndex("+PerVariableBarInde x+")",colorRed,5);// C
Plot(MACum,"\nMACum("+PerVariableCum+")",colorBlue,5);//D
Plot(AVGSum,"\nAvgSumBarcount("+BarCount+")",colorViolet,5);//E
//Plot(LastValue( AVGSum),"\nATA - LastValue("+BarCount+")",5,5); //F This
draws a horizontal line for the last value of AVGSUM
From: amibro...@yahoogrou ps.com [mailto:amibroker@ yahoogroups. com] On Behalf
Of q q
Sent: Wednesday, March 31, 2010 1:52 AM
To: amibro...@yahoogrou ps.com
Subject: RE: [amibroker] regarding cum function
Thanks joris for your reply.
(1)your AFL is perfect but when first bar is WRB then results shall vary a lot
with the point (2),of my this mail.
(2)Now coming to plot ATA(all time average average) in true spirit(from very
first bar to last one),there is no option but to plot sum(C,BarCount) .
This shall be a straight line, and the position of the selector line shall have
no effect.
(3)when a ticker falls or rises substantially on the listing day, we shall have
much difference
between your line and the line as mentioned in point no. 2. (due to neglected
first bar).
best regards
--- On Wed, 3/31/10, Joris Schuller <jschul...@charter. net> wrote:
From: Joris Schuller <jschul...@charter. net>
Subject: RE: [amibroker] regarding cum function
To: amibro...@yahoogrou ps.com
Date: Wednesday, March 31, 2010, 6:08 AM
With increased globalization we have also increased confusion and
mis-communication. As a result, I am nowadays often not sure what people
exactly are claiming and/or asking. That makes problem definition and -solution
difficult. So I will try to address what I believe you are saying. I have
added some code which should clarify this.
To summarize: All price bars are displayed correctly. Bar 1 is not used in any
computation. The indicators (MA, BarIndex, cum) are also correctly displayed,
at least starting at bar 2 and use data from bar 2 on.
1. “Cum(close) gives the same value(that of last bar) on the first bar!”
No, that’s not true at all!
This is what happens:
a. All bars and indicators are displayed correctly (with a caveat). All bars
and indicators are displayed correctly when verifying with the data series in
the Quote Editor. However, there are some peculiarities.
b. First bar of data series. The first bar of the data series (bar 1) is
correctly displayed (OHLC), as can be verified by looking at the first line in
the Quote Editor.
If you select (click on) a bar to the right (for example, bar 3) and then use
the left arrow key to move back to bar 1, the correct OHLC values will appear
in the Title. However, if you click on bar 1 it will display in the Title the
data for the last bar in the current visible range. As the code below will
show, the first bar is displayed correctly, but is not used in any computation.
BarIndex, Cum, MA, and so on start at bar 2. So, although BarIndex is 0-based
it starts effectively counting at 1 on bar 2.
b. First bar (most left bar) of any visible range. This is more of the same:
The bar itself is plotted correctly. Provided it is approached from the right
by using the left arrow key it will show the correct data in the Title for
OHLC, MA’s cum, bar index and so on. Clicking on the left most bar will again
display in the Title the values for the most right bar in the visible range.
The actual graphs (bars, Ma’s, indicators) remain correct and unchanged.
c. “want to plot the All time average line(ATA) on the price chart.But due to
cum function I get erratic line”. I presume you want to compute the avg. price
including all the bars available at that moment. So at bar 4 the MA3 of Bars
2-4, at bar (N+1) the MaN of bars 2 to N+1 (bar 1 is not used). You can use
either BarIndex or the cum function (see below).
d. Use of cum or BarIndex. As the code shows you can use either one. Nowadays
BarIndex is preferred because of apparent superior speed. I haven’t found that
so far. I tested using Code Part2 below and found calculation times for
BarIndex to be approximately 10-15% shorter than for Cum (Interpretation
window) and 30% larger ( using Formula Editor/Tools/ Code Check & Profile) and
approximately the same when including the array operator. Thus, you have an
option whether to use barindex or cum. Since there is no performance penalty
either way, I would use BarIndex not for speed, but for conformity reasons.
Title = EncodeColor(4)+ _DEFAULT_NAME()+"; "+EncodeColor(1) +
StrFormat("{{NAME}} - {{INTERVAL}} ; {{DATE}}; O=%g, H=%g, L=%g, C=%g (%.1f%%)
{{VALUES}}", O, H, L, C, SelectedValue( 10*ROC( C, 1 ) ) );
Perfixed=Param("Period Fixed",20,1,60,1);
GetPerformanceCount er(True);
{PerVariableBarInde x=(BarIndex());}//Bar Index variable
elapsed=GetPerformanceCount er();
"Bar Index: Time in ms = " + elapsed;
GetPerformanceCount er(True);
{PerVariableCum= (Cum(1)-1);} //Cum variable
elapsed=GetPerformanceCount er();
"Cum: Time in ms = " + elapsed;
MAFixed=MA(C,Perfixed);
MABarIndex=MA(C,PerVariableBarInde x);
MACum=MA(C,PerVariableCum) ;
Plot(C,"C",1,64);
Plot(MAFixed,"\nMAFixed("+Perfixed+")",colorGreen,5);
Plot(MABarIndex,"\nMABarIndex("+PerVariableBarInde x+")",colorRed,5);
Plot(MACum,"\nMACum("+PerVariableCum+")",colorBlue,5);
/*
//Code Part2. To test performance Cum vs BarIndex
Title = EncodeColor( 4)+ _DEFAULT_NAME( )+"; "+EncodeColor( 1) +
StrFormat("{{NAME}} - {{INTERVAL}} ; {{DATE}}; O=%g, H=%g, L=%g, C=%g (%.1f%%)
{{VALUES}}", O, H, L, C, SelectedValue( 10*ROC( C, 1 ) ) );
Perfixed=Param("Period Fixed",20,1,60,1);
GetPerformanceCount er(True);
for(i=1; i<10001;i++)
{PerVariableBarInde x=(BarIndex( ));}//Bar Index variable
elapsed=GetPerforma nceCounter( );
"Bar Index: Time in ms = " + elapsed;
GetPerformanceCount er(True);
for(i=1; i<10001;i++)
{PerVariableCum= (Cum(1)-1) ;} //Cum variable
elapsed=GetPerforma nceCounter( );
"Cum: Time in ms = " + elapsed;
MAFixed=MA(C, Perfixed) ;
MABarIndex=MA( C,PerVariableBar Index);
MACum=MA(C,PerVaria bleCum);
Plot(C,"C",1,64);
Plot(MAFixed,"\nMAFixed("+Perfixed+")",colorGreen, 5);
Plot(MABarIndex,"\nMABarIndex("+PerVariableBarInde x+")",colorRed,5) ;
Plot(MACum,"\nMACum("+PerVariableCum+")",colorBlue,5) ;
From: amibro...@yahoogrou ps.com [mailto:amibroker@ yahoogroups. com] On Behalf
Of war_maniac2002
Sent: Thursday, March 25, 2010 10:47 PM
To: amibro...@yahoogrou ps.com
Subject: [amibroker] regarding cum function
respected members,
Cum(close) gives the same value(that of last bar) on the first bar!
rest fine with bars in between.
Actually I want to plot the All time average line(ATA) on the price chart.
But due to cum function I get erratic line.
any solution?
regards
Send instant messages to your online friends http://uk.messenger .yahoo.com
Send instant messages to your online friends http://uk.messenger.yahoo.com