# NEOTICKER DATA BEGIN ScriptType=Indicator Description=Volume Weighted Average Price PAS Name=vwap_pas Language=DelphiScript Links=1 MinBars=0 TimerInterval=100 EarlyBinding=0 MetaStyle=Normal ValueRange=Same as Source Placement=New Pane Multiplot_num_plots=2 Multiplot_color_0=255 Multiplot_style_0=Line Multiplot_width_0=1 Multiplot_enabled_0=1 Multiplot_name_0=down color Multiplot_breakstyle_0=1 Multiplot_color_1=33619712 Multiplot_style_1=Line Multiplot_width_1=1 Multiplot_enabled_1=1 Multiplot_name_1=up color Multiplot_breakstyle_1=1 UpdateByTick=0 FloatMarker=1 DepthData=0 TradingSystemUI=0 PrimaryLinkOnly=0 NotifyOnRemoval=0 Param_count=3 Param_name_0=Price Series Param_inuse_0=1 Param_type_0=formula Param_default_0=c Param_name_1=Start Date Param_inuse_1=1 Param_type_1=datetime Param_default_1=2000/1/1 0:0:0 Param_name_2=Reset Daily Param_inuse_2=1 Param_type_2=string Param_default_2=NO|YES Explanation_Lines=1 Explanation0=Volume Weight Average Price is sum of the volume of every transaction multiplied by price of every transaction divided by the day total volume. # NEOTICKER DATA END function vwap_pas : double; Const MyHSize = 4; StartDate = 0; ResetDay = 1; AccumWVP = 2; AccumDayV = 3; var ps : variant; vwap_val : double; begin if itself.firstcall then begin heap.allocate (MyHSize); heap.fill(0, MyHSize-1, 0); if param2.datetime < data1.datetime[0] then heap.value(StartDate) := data1.datetime[0] else heap.value(StartDate) := param2.datetime; if ntlib.pos('Y',param3.str) > 0 then heap.value(ResetDay) := 1; end; ps := itself.makeindicator('ps1', 'fml', ['1'], [param1.str]); if not ps.valid[0] then begin itself.success := false; exit; end; if data1.datetime[0] < heap.value(StartDate) then begin itself.success := false; exit; end; if (ntlib.day(data1.datetime[1])<>ntlib.day(data1.datetime[0])) and (heap.value(ResetDay)>0) then begin heap.value(AccumWVP) := 0; heap.value(AccumDayV) := 0; ntlib.debug('daily rest'); end; heap.value(AccumWVP) := heap.value(AccumWVP)+ps.value[0]*data1.volume[0]; heap.value(AccumDayV) := heap.value(AccumDayV)+data1.volume[0]; if heap.value(AccumDayV)<>0 then begin vwap_val := heap.value(AccumWVP)/heap.value(AccumDayV); if vwap_val > data1.value [0] then begin itself.plot [1] := vwap_val; itself.successex [2] := false; end else begin itself.plot [2] := vwap_val; itself.successex [1] := false; end; end else itself.successall := false; end;