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 <[email protected]> wrote: From: Joris Schuller <[email protected]> Subject: RE: [amibroker] regarding cum function To: [email protected] 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
