AFL required for displaying WT AVG Price

mohan.sic

Well-Known Member
#1


Dear all,

Could anyone pls post an afl to display weighted average price of the close.

Requirement: Only Intraday.

It is NOT average for a period of time like 20 period wt. moving average or 50 period wt.moving avegrage where the last 20 candles or 50 candles closing price would be considered for calculation.

The value should be weighted average of all the closing prices available in the data till that point of time.

* ODIN, IB Power, TT advance and almost all the softwares dispalys this wt average price along with open, high, low, close ( real time). ofcouse they diaplay Wt avg price at tick level, that is every trade ( price*volume) will be considered for calculation. But here we consider close*volume , that is closing price of tha minute * volume traded during that minute.

Time Close Volume Wt avg
9:01 100 5000 100
9:02 101 10000 100.66 ( (100*5000)+(101*10000)) / (5000+10000))
9:03 102 1200 100.76 ( (100*5000)+(101*10000) + (102*1200)) / (5000+10000+1200))
Hence this is continous calculation. At anypoint of time Weighted avgerage = ( Sum of Values traded till that point / total Volume )
Value traded = ( close * Volume )


Is there any available afl for this or if not can you please send the afl code to plot wt avg price on the chart ).


Thank you.

rgds,
MoHaN.
 

asnavale

Well-Known Member
#2


Dear all,

Could anyone pls post an afl to display weighted average price of the close.

Requirement: Only Intraday.

It is NOT average for a period of time like 20 period wt. moving average or 50 period wt.moving avegrage where the last 20 candles or 50 candles closing price would be considered for calculation.

The value should be weighted average of all the closing prices available in the data till that point of time.

* ODIN, IB Power, TT advance and almost all the softwares dispalys this wt average price along with open, high, low, close ( real time). ofcouse they diaplay Wt avg price at tick level, that is every trade ( price*volume) will be considered for calculation. But here we consider close*volume , that is closing price of tha minute * volume traded during that minute.

Time Close Volume Wt avg
9:01 100 5000 100
9:02 101 10000 100.66 ( (100*5000)+(101*10000)) / (5000+10000))
9:03 102 1200 100.76 ( (100*5000)+(101*10000) + (102*1200)) / (5000+10000+1200))
Hence this is continous calculation. At anypoint of time Weighted avgerage = ( Sum of Values traded till that point / total Volume )
Value traded = ( close * Volume )


Is there any available afl for this or if not can you please send the afl code to plot wt avg price on the chart ).


Thank you.

rgds,
MoHaN.
Hi Mohan,

Do you want this AFL to work on only one day's data or for all of the days for which you have the data?

-Anant
 

asnavale

Well-Known Member
#7
Ananth sir,

Here is good description

http://stockcharts.com/help/doku.php?id=chart_school:technical_indicators:vwap_intraday


May be you can use either Typical price as given there or simply closing price of that minute in calculation.

Thank you,

MoHaN.
Hi Mohan,

Here is the AFL for calculating Weighted Close for intraday for any time frame. It works for the whole database of your intraday data. For each day the Wtd. Close is calculated separately bar-by-bar. You can use it to plot the chart and display the value in title. In that case, the Wtd Close for the bar under the selector line is displayed. You can also use it to explore and the values are displayed in the table.



_SECTION_BEGIN("WTD_CLOSE");

/************** WEIGHTED AVERAGE CLOSE PRICE **************/

SetChartOptions(0, chartShowDates | chartWrapTitle);

SetBarsRequired( sbrAll ); // If you have AmiBroker Version lower than 5.20 then delete this line completely

DN = DateNum();
PV = C * V;
CumV = Cum(V);
CumPV = Cum(PV);
WTDC = CumPV / CumV;

for(i = 1; i< BarCount; i++)
{
CumV = V + CumV[i - 1];
CumPV = PV + CumPV[i - 1];
WTDC = CumPV / CumV;
if(DN != DN[i - 1])
{
CumV = V;
CumPV = PV;
WTDC = C;
}
}



if(Status("action") == actionIndicator)
{
_N(Title = StrFormat("{{NAME}} ({{INTERVAL}} {{DATE}} {{OHLCX}}, V=%1.0f, PV=%1.2f, CumV=%1.0f, WTDC=%1.2f", V, PV, CumV, WTDC));
Plot(C, "", colorGrey50, styleBar);
}

if(Status("action") == actionExplore)
{
Filter = 1;
SetOption("NoDefaultColumns", True);
AddColumn(DateTime(), "Date", formatDateTime);
AddColumn(C, "Close", 1.2);
AddColumn(V, "Volume", 1.0);
AddColumn(CumV, "Cum.Vol.", 1.0);
AddColumn(PV, "C X Vol.", 1.2);
AddColumn(CumPV, "Sum PV", 1.2);
AddColumn(WTDC, "Wtd. Close", 1.2);
}

_SECTION_END();




Hope this helps

-Anant
 
Last edited:

asnavale

Well-Known Member
#9
Ananth sir,

Error 29
variable 'sbrAll' used without having been initialized.


regards,
mohan.
Hi Mohan,

This Error comes if you are using AmiBroker Version less than 5.20. In that case simply delete the line:

SetBarsRequired(sbrALL);

That will solve the problem.

-Anant
 

Similar threads