ATR = AverageTrueRange[inspectingPeriods](close)
currentSupplyIndex = 0
IF searchDirection = -1 THEN
candleWidth = OPEN-CLOSE
supplyLevelCandleSize = HIGHEST[inspectingPeriods](candleWidth) // GET LAST N CANDLESIZE (RED ARE POSITIVE)
IF supplyLevelCandleSize > Filterthreshold*STD[inspectingPeriods](candleWidth) THEN // FILTER
for ind = 0 to inspectingPeriods-1 DO
IF supplyLevelCandleSize = OPEN[ind]-CLOSE[ind] THEN
currentSupplyIndex = BARINDEX - ind
DRAWARROWDOWN(currentSupplyIndex,OPEN[ind]) coloured(255,0,0)
DRAWRECTANGLE(currentSupplyIndex,OPEN[ind],currentSupplyIndex+resetCounter,OPEN[ind]-ATR)coloured(255,0,0)
eventCounter = 1 // START INCREMENTING
demandOrSupplyZoneStart = OPEN[ind] // RETURN VALUE AT THE END
demandOrSupplyZoneEnd = OPEN[ind]-ATR // RETURN VALUE AT THE END
supplyOrDemand = searchDirection // RETURN VALUE AT THE END
BREAK // conditions met, exit loop
ENDIF
NEXT
ENDIF
ENDIF