DEFPARAM DRAWONLASTBARONLY=TRUE
MaxSegments2show=max(0,Segments2show-2) //points top/low back to store
// initialisation
once LastZigZag = 1
once ZigZagIndex = 0
once $ZigZagX[ZigZagIndex]=barindex
once $ZigZagY[ZigZagIndex]=High
// Variation de prix en fonction de l'ATD et de la déviation standart
DeltaY=max(7,(AverageTrueRange[period](close)+STD[period](close))*facteur)
// Vague haussière en cours
if LastZigZag=1 then
if High>$ZigZagY[ZigZagIndex] then
$ZigZagY[ZigZagIndex]=High
$ZigZagX[ZigZagIndex]=barindex
elsif Low<=($ZigZagY[ZigZagIndex]-DeltaY) then // New ZigZag, changement de vague
ZigZagIndex=ZigZagIndex+1
$ZigZagY[ZigZagIndex]=Low
$ZigZagX[ZigZagIndex]=barindex
LastZigZag=-1
endif
endif
// Vague baissière en cours
if LastZigZag=-1 then //lastpoint was a low
if Low<$ZigZagY[ZigZagIndex] then
$ZigZagY[ZigZagIndex]=low
$ZigZagX[ZigZagIndex]=barindex
elsif High>=($ZigZagY[ZigZagIndex]+DeltaY) then // New ZigZag, changement de vague
ZigZagIndex=ZigZagIndex+1
$ZigZagY[ZigZagIndex]=High
$ZigZagX[ZigZagIndex]=barindex
LastZigZag=1
endif
endif
FirstSegment=max(1,ZigZagIndex-MaxSegments2show)
// Zigzag Drawing
If LastZigZag=1 then
drawsegment (barindex,Low,$ZigZagX[ZigZagIndex],$ZigZagY[ZigZagIndex]) style(dottedline,2) COLOURED ("tomato",200) //segment in progress
If ZigZagIndex>1 then
For i= ZigZagIndex downto FirstSegment do
If $ZigZagY[i]>$ZigZagY[i-1] then
drawsegment($ZigZagX[i],$ZigZagY[i],$ZigZagX[i-1],$ZigZagY[i-1]) style(line,2) COLOURED("dodgerblue",200)
Else
drawsegment($ZigZagX[i],$ZigZagY[i],$ZigZagX[i-1],$ZigZagY[i-1]) style(line,2) COLOURED("tomato",200)
Endif
Next
Endif
Endif
If LastZigZag=-1 then
drawsegment (barindex,High,$ZigZagX[ZigZagIndex],$ZigZagY[ZigZagIndex]) style (dottedline,2) COLOURED ("dodgerblue",200) //segment in progress
If ZigZagIndex>1 then
For i= ZigZagIndex downto FirstSegment do
If $ZigZagY[i]>$ZigZagY[i-1] then
drawsegment($ZigZagX[i],$ZigZagY[i],$ZigZagX[i-1],$ZigZagY[i-1]) style(line,2) COLOURED("dodgerblue",200)
Else
drawsegment($ZigZagX[i],$ZigZagY[i],$ZigZagX[i-1],$ZigZagY[i-1]) style(line,2) COLOURED("tomato",200)
Endif
Next
Endif
Endif
return