// Indicator Parameters
Period = 48
CandleStart = 030001
CandleStop = 030059
ONCE startIndex = 0
ONCE CandleOpen = Open
ONCE CandleClose = Close
ONCE CandleHigh = High
ONCE CandleLow = Low
IF CurrentTime > CandleStart AND CurrentTime < CandleStop AND BarIndex > Period THEN
startIndex = BarIndex
ENDIF
IF BarIndex - startIndex > Period THEN
startIndex = BarIndex
ENDIF
// Current Bar Position
IF startIndex > 0 THEN
currentBar = abs(BarIndex - startIndex)
ELSE
currentBar = abs(BarIndex)
ENDIF
// Calculate 4 Hr Open
IF startIndex > 0 THEN
CandleOpen = Open[currentBar]
ENDIF
// Calculate 4 Hr Close
IF startIndex > 0 THEN
CandleClose = Close[currentBar]
ENDIF
// Calculate 4 Hr High
IF startIndex > 0 THEN
CandleHigh = highest[currentBar]
ENDIF
// Calculate 4 Hr Low
IF startIndex > 0 THEN
CandleLow = lowest[currentBar]
ENDIF
// Draw Candle
//candlestick color
if CandleOpen>CandleClose then
direction = -1
else
direction = 1
endif
if direction = 1 then
// Candlestick body
DRAWRECTANGLE(barindex-5,CandleOpen,barindex,CandleClose) COLOURED(10,255,10)
// Candlestick high and low
DRAWRECTANGLE(barindex-3,CandleClose,barindex-2,CandleHigh) COLOURED(10,255,10)
DRAWRECTANGLE(barindex-3,CandleOpen,barindex-2,CandleLow) COLOURED(10,255,10)
endif
//bearish candle
if direction = -1 then
// Candlestick body
DRAWRECTANGLE(barindex-5,CandleClose,barindex,CandleOpen) COLOURED(255,10,10)
// Candlestick high and low
DRAWRECTANGLE(barindex-3,CandleOpen,barindex-2,CandleHigh) COLOURED(255,10,10)
DRAWRECTANGLE(barindex-3,CandleClose,barindex-2,CandleLow) COLOURED(255,10,10)
endif
return CandleOpen as "CandleOpen", CandleClose as "CandleClose", CandleHigh as "CandleHigh", CandleLow as "CandleLow"