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);
GetPerformanceCounter(True);
{PerVariableBarIndex=(BarIndex());}//Bar Index variable
elapsed=GetPerformanceCounter();
"Bar Index: Time in ms = " + elapsed;
GetPerformanceCounter(True);
{PerVariableCum=(Cum(1)-1);} //Cum variable
elapsed=GetPerformanceCounter();
"Cum: Time in ms = " + elapsed;
MAFixed=MA(C,Perfixed);
MABarIndex=MA(C,PerVariableBarIndex);
MACum=MA(C,PerVariableCum);
Plot(C,"C",1,64);
Plot(MAFixed,"\nMAFixed("+Perfixed+")",colorGreen,5);
Plot(MABarIndex,"\nMABarIndex("+PerVariableBarIndex+")",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);
GetPerformanceCounter(True);
for(i=1; i<10001;i++)
{PerVariableBarIndex=(BarIndex());}//Bar Index variable
elapsed=GetPerformanceCounter();
"Bar Index: Time in ms = " + elapsed;
GetPerformanceCounter(True);
for(i=1; i<10001;i++)
{PerVariableCum=(Cum(1)-1);} //Cum variable
elapsed=GetPerformanceCounter();
"Cum: Time in ms = " + elapsed;
MAFixed=MA(C,Perfixed);
MABarIndex=MA(C,PerVariableBarIndex);
MACum=MA(C,PerVariableCum);
Plot(C,"C",1,64);
Plot(MAFixed,"\nMAFixed("+Perfixed+")",colorGreen,5);
Plot(MABarIndex,"\nMABarIndex("+PerVariableBarIndex+")",colorRed,5);
Plot(MACum,"\nMACum("+PerVariableCum+")",colorBlue,5);
From: [email protected] [mailto:[email protected]] On Behalf
Of war_maniac2002
Sent: Thursday, March 25, 2010 10:47 PM
To: [email protected]
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