tf = Param("Ref TF", 60, 1, 100000, 1) ;
Clrhigh = ParamColor("Color High", colorRed) ;
Clrlow = ParamColor("Color Low", colorBlue) ;
Clrpvt = ParamColor("Color Pivot", colorYellow) ;
showproj = ParamToggle("Show Projection", "No|Yes", 1) ;
showpvt = ParamToggle("Show Pvt", "No|Yes", 1) ;
showsec = ParamToggle("Show Secondary", "No|Yes", 1) ;
shownext = ParamToggle("Show Next", "No|Yes", 0) ;
tfs = tf * in1Minute ;
TimeFrameSet(tfs) ;
Refp = IIf(C > O, H, IIf(C < L, L, C)) ;
x = (H+L+C+Refp) / 2 ;
range = H-L ;
projhigh = Ref(x, -1) - Ref(L, -1) ;
projlow = Ref(x, -1) - Ref(H, -1) ;
nexth = x - L ;
nextl = x - H ;
Lastbar = BarIndex() == BarCount-1;
H2 = Ref(x,-1)/2+Ref(range, -1) ;
L2 = Ref(x, -1)/2-Ref(range, -1) ;
x0 = Ref(x,-1)/2 ;
TimeFrameRestore() ;
phe = TimeFrameExpand(projhigh, tfs, expandFirst) ;
ple = TimeFrameExpand(projlow, tfs, expandFirst) ;
H2e = TimeFrameExpand(H2, tfs, expandFirst) ;
L2e = TimeFrameExpand(L2, tfs, expandFirst) ;
x0e = TimeFrameExpand(x0, tfs, expandFirst) ;
Nullat = x0e != Ref(x0e, 1) ;
nexthe = TimeFrameExpand(nexth , tfs, expandFirst) ;
nextle = TimeFrameExpand(nextl , tfs, expandFirst) ;
nextpe = TimeFrameExpand(x/2, tfs, expandFirst) ;
Lastbare = TimeFrameExpand(Lastbar , tfs, expandFirst) ;
if (showproj)
{
Plot(IIf(nullat, Null, phe), "", Clrhigh, styleThick|styleDots|styleNoRescale|styleNoTitle) ;
Plot(IIf(nullat, Null, ple), "", Clrlow, styleThick|styleDots|styleNoRescale|styleNoTitle) ;
}
if (showsec)
{
Plot(IIf(nullat, Null, H2e), "", Clrhigh, styleThick|styleNoRescale|styleNoTitle) ;
Plot(IIf(nullat, Null, L2e), "", Clrlow, styleThick|styleNoRescale|styleNoTitle) ;
}
if (showpvt)
Plot(IIf(nullat, Null, x0e), "", Clrpvt, styleThick|styleDots|styleNoRescale|styleNoTitle) ;
if (shownext)
{
Plot(IIf (Lastbare , nexthe, Null) , "", Clrhigh, styleThick|styleDashed|styleNoRescale|styleNoTitle) ;
Plot(IIf (Lastbare , nextle, Null), "", Clrlow, styleThick|styleDashed|styleNoRescale|styleNoTitle) ;
Plot(IIf (Lastbare , nextpe, Null), "", Clrpvt, styleThick|styleDashed|styleNoRescale|styleNoTitle) ;
}