# NEOTICKER DATA BEGIN ScriptType=Indicator Description=Example zigzag Delphi source Name=ex_del_zigzag Language=DelphiScript Links=1 MinBars=0 TimerInterval=100 EarlyBinding=0 MetaStyle=Normal ValueRange=Same as Source Placement=Smart Multiplot_num_plots=3 Multiplot_color_0=255 Multiplot_style_0=Line Multiplot_width_0=1 Multiplot_enabled_0=1 Multiplot_breakstyle_0=0 Multiplot_color_1=255 Multiplot_style_1=Line Multiplot_width_1=1 Multiplot_enabled_1=1 Multiplot_breakstyle_1=0 Multiplot_color_2=255 Multiplot_style_2=Line Multiplot_width_2=1 Multiplot_enabled_2=1 Multiplot_breakstyle_2=0 UpdateByTick=0 FloatMarker=1 TradingSystemUI=0 PrimaryLinkOnly=0 NotifyOnRemoval=0 Param_count=6 Param_name_0=Type Param_inuse_0=1 Param_type_0=string Param_default_0=Percent|Point Param_name_1=Diff Param_inuse_1=1 Param_type_1=real Param_default_1=5 Param_name_2=Up Color Param_inuse_2=1 Param_type_2=color Param_default_2=16744448 Param_name_3=Dn Color Param_inuse_3=1 Param_type_3=color Param_default_3=255 Param_name_4=Last Color Param_inuse_4=1 Param_type_4=color Param_default_4=65280 Param_name_5=Line Width Param_inuse_5=1 Param_type_5=integer.gt.0 Param_default_5=2 Explanation_Lines=0 # NEOTICKER DATA END function ex_del_zigzag : double; var pdiff_up, pdiff_down, pdiff : real; samebar, push_swing, type_percent, use_confirm, is_temp : boolean; current_line_id, curr_pos, dist_pos, target_pos, new_line, temp_pos, d_from , d_to, i : integer; s, u : string; const PHeapSize = 17; Param_upColor = 0; Param_dnColor = 1; Param_lastColor = 2; Param_ZigType = 5; Param_Diff = 6; Param_Width = 7; RT_LineID = 8; RT_LastBar = 9; RT_LineOnLastBar = 10; RT_LastWasTemp = 11; Line_Direction = 12; Line_OldSwingPt = 13; Line_PrevSwingPt = 14; Line_CurrSwingPt = 15; Line_TempSwingPt = 16; PriceNu = 0; PriceUp = 1; PriceDown = -1; begin if not data1.valid [0] then begin itself.successex [1] := false; itself.successex [2] := false; itself.successex [3] := false; exit; end; if pheap.size = 0 then begin pheap.allocate (PHeapSize); pheap.fill (0, PHeapSize - 1, 0); pheap.value [Param_upColor] := params.items ['Up Color'].color; pheap.value [Param_dnColor] := params.items ['Dn Color'].color; pheap.value [Param_lastColor] := params.items ['Last Color'].color; s := params.items ['Type'].str; u := uppercase (s); if u = 'PERCENT' then pheap.value [Param_ZigType] := 1; pheap.value [Param_Diff] := params.items ['Diff'].real; pheap.value [Param_Width] := params.items ['Line Width'].real; pheap.value [RT_LineID] := -1; pHeap.value [Line_Direction] := PriceNu; pHeap.value [Line_OldSwingPt] := data1.Barsnum [0]; pHeap.value [Line_PrevSwingPt] := data1.Barsnum [0]; pHeap.value [Line_CurrSwingPt] := data1.Barsnum [0]; pHeap.value [Line_TempSwingPt] := data1.Barsnum [0]; drawingobjects.deleteall; end; // determine direction of move new_line := 0; push_swing := false; is_temp := false; curr_pos := data1.barsnum [0] - round (pHeap.value [Line_PrevSwingPt]); dist_pos := data1.barsnum [0] - round (pHeap.value [Line_CurrSwingPt]); temp_pos := data1.barsnum [0] - round (pheap.value [Line_TempSwingPt]); pdiff := pheap.value [Param_Diff]; samebar := (tq_round (pheap.value [RT_LastBar]) = itself.currentbar [0]); if pheap.value [Param_ZigType] = 1 then // is percent type begin pdiff_up := (Data1.High [0] - data1.low [dist_pos]) / data1.low [dist_pos] * 100; pdiff_down := (Data1.Low [0] - data1.high [dist_pos]) / data1.high [dist_pos] * 100; end else begin pdiff_up := Data1.High [0] - data1.low [dist_pos]; pdiff_down := Data1.Low [0] - data1.high [dist_pos]; end; // find new line direction if pHeap.value [Line_Direction] = PriceNu then begin // find first move direction if pdiff_up >= pdiff then begin new_line := 1; push_swing := true; end else if (- pdiff_down) >= pdiff then begin new_line := -1; push_swing := true; end; end else if pHeap.value [Line_Direction] = PriceUp then begin if (dist_pos > 0) and ((- pdiff_down) >= pdiff) then // check if turn around begin new_line := -1; push_swing := true; end else // check if continuation begin if data1.high [dist_pos] < data1.high [0] then // further the move begin new_line := 1; pheap.value [Line_CurrSwingPt] := data1.barsnum [0]; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if samebar and (dist_pos = 0) then // update real-time changes begin new_line := 1; end else if data1.islastbar and (dist_pos > 0) then begin if dist_pos = 1 then begin is_temp := true; new_line := -1; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if data1.low [temp_pos] > data1.low [0] then begin is_temp := true; new_line := -1; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if samebar and (temp_pos = 0) then begin is_temp := true; new_line := -1; end; end; end; end else if pHeap.value [Line_Direction] = PriceDown then begin if (dist_pos > 0) and (pdiff_up > pdiff) then // check if turn around begin new_line := 1; push_swing := true; end else // check if continuation begin if data1.low [dist_pos] > data1.low [0] then // further the move begin new_line := -1; pheap.value [Line_CurrSwingPt] := data1.barsnum [0]; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if samebar and (dist_pos = 0) then // update real-time changes begin new_line := -1; end else if data1.islastbar and (dist_pos > 0) then begin if dist_pos = 1 then begin is_temp := true; new_line := 1; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if data1.high [temp_pos] < data1.high [0] then begin is_temp := true; new_line := 1; pheap.value [Line_TempSwingPt] := data1.barsnum [0]; end else if samebar and (temp_pos = 0) then begin is_temp := true; new_line := 1; end; end; end; end; // draw line now current_line_id := -1; // if new_line <> 0 then // ready to draw begin if pheap.value [RT_LastWasTemp] <> 0 then begin drawingobjects.delete (round (pheap.value [RT_LineID])); pheap.value [RT_LineID] := -1; pheap.value [RT_LineOnLastBar] := 0; pheap.value [RT_LastWasTemp] := 0; end; if pheap.value [Line_Direction] = new_line then begin drawingobjects.delete (drawingobjects.count - 1); end; if push_swing then begin pheap.value [line_oldswingpt] := pheap.value [line_prevswingpt]; pheap.value [line_prevswingpt] := pheap.value [line_currswingpt]; pheap.value [line_currswingpt] := data1.barsnum [0]; pheap.value [line_tempswingpt] := data1.barsnum [0]; current_line_id := - 1; // need new line end; if current_line_id < 0 then begin if pHeap.value [Param_Width] <> 0 then begin current_line_id := drawingobjects.add (cotTrendLine); drawingobjects.autoremoveonupdatebytick [current_line_id] := false; end; end; if is_temp then begin d_from := data1.barsnum [0] - round (pheap.value [line_currswingpt]); d_to := data1.barsnum [0] - round (pheap.value [line_tempswingpt]); end else begin d_from := data1.barsnum [0] - round (pheap.value [line_prevswingpt]); d_to := data1.barsnum [0] - round (pheap.value [line_currswingpt]); end; if (current_line_id >= 0) and ((d_from - d_to) > 0) then with drawingobjects do begin if new_line > 0 then begin if is_temp then color [current_line_id] := trunc (pheap.value [param_lastcolor]) else color [current_line_id] := trunc (pheap.value [param_upcolor]); setpoint (current_line_id, 0, data1.datetime [d_from], data1.low [d_from]); setpoint (current_line_id, 1, data1.datetime [d_to], data1.high [d_to]); end else begin if is_temp then color [current_line_id] := trunc (pheap.value [param_lastcolor]) else color [current_line_id] := trunc (pheap.value [param_dncolor]); setpoint (current_line_id, 0, data1.datetime [d_from], data1.high [d_from]); setpoint (current_line_id, 1, data1.datetime [d_to], data1.low [d_to]); end; penwidth [current_line_id] := round (pHeap.value [Param_Width]); visible [current_line_id] := true; end; pheap.value [RT_LineID] := current_line_id; pheap.value [RT_LineOnLastBar] := itself.currentbar [0]; if is_temp then begin pheap.value [RT_LastWasTemp] := 1; end else begin pheap.value [RT_LastWasTemp] := 0; pheap.value [line_direction] := new_line; end; end; if pheap.value [Line_Direction] > 0 then begin i := data1.barsnum [0] - round (pheap.value [Line_currSwingPt]); itself.plot [1] := data1.high [i]; itself.plot [2] := i; itself.plot [3] := 1; end else if pheap.value [Line_Direction] < 0 then begin i := data1.barsnum [0] - round (pheap.value [Line_currSwingPt]); itself.plot [1] := data1.low [i]; itself.plot [2] := i; itself.plot [3] := -1; end else begin itself.successex [1] := false; itself.successex [2] := false; itself.successex [3] := false; end; pheap.value [RT_LastBar] := itself.currentbar [0]; end;