// Pivot Support & Resistance Bands
//
//
DEFPARAM CalculateOnLastBars = 1000
//p = 2 //2 periods
//Type = 1 //1 = Ema
p = max(1,min(999,p)) //range 1 - 999
Type = max(0,min(6,Type)) //range 0 - 6
PivotBAR = 2 //2 bars AFTER pivot PASSAGE A 0 AU LIEU DE 2
LookBack = 4 //4 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
EmaResistance = average[p,Type](ResistancePrice)
EmaSupport = average[p,Type](SupportPrice)
MidLine = EmaSupport + ((EmaResistance - EmaSupport) / 2)
//DRAWSEGMENT(MyResistance,ResistancePrice,BarIndex,ResistancePrice) COLOURED(255,0,0,255)
//DRAWSEGMENT(MySupport,SupportPrice,BarIndex,SupportPrice) COLOURED(0,128,0,255)
RETURN EmaResistance COLOURED(255,0,0,255) AS "EmaResistance",EmaSupport COLOURED(0,255,0,255) AS "EmaSupport",MidLine coloured(0,0,0,255) AS "MidLine"