/**************************************
******** PREV SESSION'S HLC ***********
****************************************/
_SECTION_BEGIN("Two Day Range");
// Get Previous Day's High low and Close
PrevHigh = TimeFrameGetPrice("H", inDaily, -1);
PrevLow = TimeFrameGetPrice("L", inDaily, -1);
PrevClose = TimeFrameGetPrice("C", inDaily, -1);
// Get Previous 2 Day's High low and Close
Prev2High = TimeFrameGetPrice("H", inDaily, -2);
Prev2Low = TimeFrameGetPrice("L", inDaily, -2);
Prev2Close = TimeFrameGetPrice("C", inDaily, -2);
// Check bar's time
CurrBarTime = TimeNum();
DayStartTime = 91500;
DayEndTime = 153000;
// Check range condition
IsAllDay = CurrBarTime >= DayStartTime AND CurrBarTime <= DayEndTime;
IsToday = Day() == LastValue(Day()) AND Month() == LastValue(Month());
ShowPrevHLC = ParamToggle("Show Previous day Range", "Yes|No", 1);
ShowTwoDayRange = ParamToggle("Show Two Day Range", "Yes|No", 1);
ColorPrevDayRange = ParamColor("Previous Day Range Color", colorTurquoise);
ColorPrev2DayRange = ParamColor("Previous 2Day Range Color", colorGold);
x= Cum(1);
PDHbi = LastValue(ValueWhen(H==LastValue(PrevHigh), x));
PDH = IIf(x>PDHbi, ValueWhen(H==LastValue(PrevHigh), High), Null);
PDHO = IIf(x>PDHbi, ValueWhen(H==LastValue(PrevHigh), Open), Null);
PDHC = IIf(x>PDHbi, ValueWhen(H==LastValue(PrevHigh), Close), Null);
PDLbi = LastValue(ValueWhen(L==LastValue(prevLow), x));
PDL = IIf(x>PDLbi, ValueWhen(L==LastValue(prevLow), Low), Null);
PDLO = IIf(x>PDLbi, ValueWhen(L==LastValue(PrevLow), Open), Null);
PDLC = IIf(x>PDLbi, ValueWhen(L==LastValue(PrevLow), Close), Null);
P2DHbi = LastValue(ValueWhen(H==LastValue(Prev2High), x));
TwoDH = IIf(x>P2DHbi, ValueWhen(H==LastValue(Prev2High), High), Null);
TwoDHO = IIf(x>P2DHbi, ValueWhen(H==LastValue(Prev2High), Open), Null);
TwoDHC = IIf(x>P2DHbi, ValueWhen(H==LastValue(Prev2High), Close), Null);
P2DLbi = LastValue(ValueWhen(L==LastValue(Prev2Low), x));
TwoDL = IIf(x>P2DLbi, ValueWhen(L==LastValue(Prev2Low), Low), Null);
TwoDLO = IIf(x>P2DLbi, ValueWhen(L==LastValue(Prev2Low), Open), Null);
TwoDLC = IIf(x>P2DLbi, ValueWhen(L==LastValue(Prev2Low), Close), Null);
if(ShowPrevHLC AND Interval() <= 3600)
{
Plot(PDH, "", ColorPrevDayRange, styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
Plot(PDL, "", ColorPrevDayRange, styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
PlotOHLC(PDH,PDH,Max(PDHO, PDHC),Max(PDHO, PDHC),"", ColorBlend(ColorPrevDayRange, GetChartBkColor(), 0.9),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
PlotOHLC(PDL,PDL,Min(PDLO, PDLC),Min(PDLO, PDLC),"", ColorBlend(ColorPrevDayRange, GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
Plot(IIf(IsToday, PrevClose,Null), "", colorBlack, styleDashed|styleNoRescale|styleNoTitle|styleNoLabel);
}
if(ShowTwoDayRange AND Interval() <= 3600)
{
Plot(TwoDH, "", ColorPrev2DayRange , styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
Plot(TwoDL, "", ColorPrev2DayRange , styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
PlotOHLC(TwoDH,TwoDH,Max(TwoDHO, TwoDHC),Max(TwoDHO, TwoDHC),"", ColorBlend(ColorPrev2DayRange , GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
PlotOHLC(TwoDL,TwoDL,Min(TwoDLO, TwoDLC),Min(TwoDLO, TwoDLC),"", ColorBlend(ColorPrev2DayRange , GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
}