# NEOTICKER DATA BEGIN ScriptType=Indicator Description=Parabolic SAR Ex Source Name=parabolicex_source 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=Dot Multiplot_width_0=1 Multiplot_enabled_0=1 Multiplot_breakstyle_0=0 UpdateByTick=0 TradingSystemUI=0 PrimaryLinkOnly=0 NotifyOnRemoval=0 Param_count=2 Param_name_0=Factor Param_inuse_0=1 Param_type_0=real Param_default_0=0.02 Param_name_1=Max Param_inuse_1=1 Param_type_1=real Param_default_1=0.2 Explanation_Lines=0 # NEOTICKER DATA END function parabolicex_source : double; var op : integer; // direction of last bar hi, lo : double; sar : double; af : double; addf : double; begin if not data1.valid [0] then begin itself.success := false; exit; end; // initialization if heap.size = 0 then begin heap.allocate(5); heap.fill(0,4,0); heap.value [0] := 1; // assume SAR long to start heap.value [0] := data1.open [0]; heap.value [1] := data1.high [0]; heap.value [2] := data1.low [0]; heap.value [4] := data1.close [0]; itself.success := false; exit; end; // previous direction op := trunc (heap.value [0]); hi := heap.value [1]; lo := heap.value [2]; af := heap.value [3]; // Replace high with higher high and lower with lower low if data1.high [0] > hi then hi := data1.high [0]; if data1.low [0] < lo then lo := data1.low [0]; // switch direction when high or low of previous day // cross over parabolic line if heap.value [0] = 1 then begin if data1.low [0] <= heap.value [4] then heap.value [0] := -1; end // if else begin if data1.high [0] >= heap.value [4] then heap.value [0] := 1; end; // else if heap.value [0] = 1 then // SAR long begin if op <> 1 then // switch from long to short begin sar := lo; lo := data1.low [0]; hi := data1.high [0]; af := param1.real; end else begin sar := itself.value[1] + af * (hi - itself.value[1]); if (hi > heap.value[1]) and (af < param2.real) then begin // find Min of afactor and 0.2-af addf := param2.real - af; if addf > param1.real then addf := param1.real; af := af + addf; end; end; if sar > data1.low [0] then sar := data1.low [0]; if sar > data1.low [1] then sar := data1.low [1]; end else begin if op <> -1 then // switch from short to long begin sar := hi; lo := data1.low [0]; hi := data1.high [0]; af := param1.real; end else begin sar := itself.value [1] + af * (lo - itself.value[1]); if (lo < heap.value[2]) and (af < param2.real) then begin addf := param2.real - af; if addf > param1.real then addf := param1.real; af := af + addf; end; end; if sar < data1.high [0] then sar := data1.high [0]; if sar < data1.high [1] then sar := data1.high [1]; end; result := sar; heap.value[1] := hi; heap.value[2] := lo; heap.value[3] := af; heap.value[4] := sar; end;