# NEOTICKER DATA BEGIN ScriptType=Indicator Description=Profile Average Name=ProfileAverage Language=DelphiScript Links=1 MinBars=0 TimerInterval=100 MetaStyle=Normal ValueRange=Same as Source Placement=Smart Multiplot_num_plots=1 Multiplot_color_0=255 Multiplot_style_0=Line Multiplot_width_0=1 Multiplot_enabled_0=1 Multiplot_breakstyle_0=0 UpdateByTick=1 TradingSystemUI=0 PrimaryLinkOnly=0 NotifyOnRemoval=0 Param_count=2 Param_name_0=Period Param_inuse_0=1 Param_type_0=integer.gt.0 Param_default_0=30 Param_name_1=SlotSize Param_inuse_1=1 Param_type_1=real Param_default_1=0.25 Explanation_Lines=1 Explanation0=Profile Average plots the average price based on the moving profile defined by the parameter Period and Slot Size. Profile Average requires one series (Link 1). # NEOTICKER DATA END function ProfileAverage : double; var i, period, c, offset : integer; md, stddev : double; begin period := param1.int; if heap.size = 0 then begin heap.allocate (period + 2); heap.fill (0, period + 1, 0); heap.allocatepriceprofile ('a', param2.real, data1.low [0], data1.high [0]); end; if not data1.valid [0] then begin itself.successall := false; exit; end; i := heap.value [period]; c := heap.value [period + 1]; // once we filled up the cyclical buffer, it is time to // remove the oldest values from the profile if c >= period then begin offset := data1.barsnum [0] - heap.value [i]; heap.priceprofileremovepricerange ( 'a', data1.low [offset], data1.high [offset], data1.volume [offset]); end; // update profile with latest volume information heap.value [i] := data1.barsnum [0]; heap.priceprofileaddpricerange ('a', data1.low [0], data1.high [0], data1.volume [0]); // the indices into the cyclical buffer is adjusted for the next update heap.value [period + 1] := c + 1; heap.value [period] := (i + 1) mod period; // our indicator value is simply the volume weighted average price // of the profile md := heap.priceprofilevwap ('a'); itself.plot [1] := md; end;