Code:
/**************************************
******** 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);
PrevRangeStyle = ParamToggle("Previous day range style", "Lines|Range", 0);
ShowTwoDayRange = ParamToggle("Show Two Day Range", "Yes|No", 1);
Prev2RangeStyle = ParamToggle("Previous 2day range style", "Lines|Range", 0);
ColorRangeHigh = ParamColor("Range High Color", colorBlue);
ColorRangeLow = ParamColor("Range Low Color", colorRed);
// Zone Calculation
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);
// Show or Hide Previous Day Range
if(ShowPrevHLC AND Interval() <= 3600)
{
// Previous Day as Lines
if(PrevRangeStyle)
{
Plot(IIf(IsToday,PrevHigh,Null),"",ColorRangeHigh,styleLine|styleThick|styleDashed|styleNoRescale|styleNoLabel);
Plot(IIf(IsToday,PrevLow,Null),"",ColorRangeLow ,styleLine|styleThick|styleDashed|styleNoRescale|styleNoLabel);
Plot(IIf(IsToday,PrevClose,Null),"",colorBlack,styleLine|styleThick|styleDashed|styleNoRescale|styleNoLabel);
}
// Prewvious Day as Range
else
{
Plot(PDH, "", ColorRangeHigh, styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
Plot(PDL, "", ColorRangeLow , styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
PlotOHLC(PDH,PDH,Max(PDHO, PDHC),Max(PDHO, PDHC),"", ColorBlend(ColorRangeHigh, GetChartBkColor(), 0.9),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
PlotOHLC(PDL,PDL,Min(PDLO, PDLC),Min(PDLO, PDLC),"", ColorBlend(ColorRangeLow, GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
Plot(IIf(IsToday, PrevClose,Null), "", colorBlack, styleDashed|styleNoRescale|styleNoTitle|styleNoLabel);
}
// Prev Day Rnage Text
PlotText("PDH - " + NumToStr(PrevHigh,1.11), BarCount+1, LastValue(PrevHigh),ColorRangeHigh );
PlotText("PDL - " + NumToStr(PrevLow,1.11), BarCount+1, LastValue(PrevLow),ColorRangeLow);
PlotText("PDC - " + NumToStr(PrevClose,1.11), BarCount+1, LastValue(PrevClose),colorBlack);
}
// Show or Hide 2 Day Range
if(ShowTwoDayRange AND Interval() <= 3600)
{
// 2 Day range as Line
if(Prev2RangeStyle)
{
Plot(IIf(IsToday,Prev2High ,Null),"",ColorRangeHigh ,styleLine|styleDashed|styleNoRescale|styleNoLabel);
Plot(IIf(IsToday,Prev2Low,Null),"",ColorRangeLow,styleLine|styleDashed|styleNoRescale|styleNoLabel);
}
// 2 Day Range as Zone
else
{
Plot(TwoDH, "", ColorRangeHigh , styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
Plot(TwoDL, "", ColorRangeLow, styleLine|styleNoTitle|styleNoLabel|styleNoRescale);
PlotOHLC(TwoDH,TwoDH,Max(TwoDHO, TwoDHC),Max(TwoDHO, TwoDHC),"", ColorBlend(ColorRangeHigh , GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
PlotOHLC(TwoDL,TwoDL,Min(TwoDLO, TwoDLC),Min(TwoDLO, TwoDLC),"", ColorBlend(ColorRangeLow, GetChartBkColor(), 0.8),styleNoRescale|styleCloud|styleNoLabel,Null, Null, 0, -5, 5);
}
// 2 Day Range TExt
PlotText("2DH - " + NumToStr(Prev2High ,1.11), BarCount+1, LastValue(Prev2High ),ColorRangeHigh );
PlotText("2DL - " + NumToStr(Prev2Low,1.11), BarCount+1, LastValue(Prev2Low),ColorRangeLow);