Average percent

#1
This is the output from an Exploration I have. Last column "Percent H-L" shows the difference in percent between High and Low price each trading day.

Ticker Date/Time Closing price Percent H-L
STL.OL 31.10.2014 153,00 3,29
STL.OL 03.11.2014 152,20 1,97
STL.OL 04.11.2014 147,10 2,24
STL.OL 05.11.2014 150,20 3,08
STL.OL 06.11.2014 149,40 2,07
STL.OL 07.11.2014 152,20 2,20
STL.OL 10.11.2014 153,10 2,43
STL.OL 11.11.2014 152,00 1,72
STL.OL 12.11.2014 151,30 1,33
STL.OL 13.11.2014 148,40 1,88
STL.OL 14.11.2014 149,40 3,60

My question is:
How do I write the Afl (Exploration) that shows the average percent from first to last trading day at the bottom of the column "Percent H-L"?

The Exploration is like this:

condi1 = ((H - L) * 100) / L;
Filter = condi1;
AddColumn(Close, "Closing price",1.2);
AddColumn(condi1, "Percent H-L", 1.2);

Anyone that can help?

Regards
donjoe
 

trash

Well-Known Member
#2
There are two ways:

Either use
AddSummaryRows http://www.amibroker.com/guide/afl/addsummaryrows.html
or own formula.



Code:
// http://www.traderji.com/amibroker/96252-average-percent.html
// solution by trash

condi1 = (H - L) / L * 100;

Filter = condi1 > 1 AND Status( "barinrange" );

AddColumn( Close, "Closing price", 1.2 );
AddColumn( condi1, "Percent H-L", 1.2 );

AvgPerc = Cum( IIf( Filter, condi1, 0 ) ) / Cum( Filter );
AddColumn( AvgPerc, "Avg.Percent", 1.2 );

// http://www.amibroker.com/guide/afl/addsummaryrows.html
AddSummaryRows( 2, 1.2, column = 4 ); // just average
//AddSummaryRows( 63, 1.2, column = 4 ); // all options
 
Last edited:

Similar threads