DEFPARAM CalculateOnLastBars = 1000
PivotBAR = 2 //2 bars AFTER pivot
LookBack = 4 //3 bars BEFORE pivot
BarLookBack = PivotBAR + 1
IF low[PivotBAR] < lowest[LookBack](low)[BarLookBack] THEN
IF low[PivotBAR] = lowest[BarLookBack](low) THEN
MySupport = BarIndex - PivotBAR
SupportPrice = low[PivotBAR]
ENDIF
ENDIF
IF high[PivotBAR] > highest[LookBack](high)[BarLookBack] THEN
IF high[PivotBAR] = highest[BarLookBack](high) THEN
MyResistance = BarIndex - PivotBAR
ResistancePrice = high[PivotBAR]//high[BarIndex - MyResistance]
ENDIF
ENDIF
DRAWSEGMENT(MyResistance,ResistancePrice,BarIndex,ResistancePrice) COLOURED(255,0,0,255)
DRAWSEGMENT(MySupport,SupportPrice,BarIndex,SupportPrice) COLOURED(0,128,0,255)
RETURN