_SECTION_BEGIN("Visual Pivots");
// Author: Pratap Balakrishnan
// Copyright: All rights reserved. Not to be circulated or shared or posted on websites without the author's written permission.
// email id: [email][email protected][/email]
//
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
SetChartBkColor( ParamColor("BKGrnd", ColorRGB( 190, 190, 190 ) ) );
Plot( C, "Close", ParamColor("Candle Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
ro = ParamField("Open", 0) ;
rh = ParamField("High", 1) ;
rl = ParamField("Low", 2) ;
rc = ParamField("Close", 3) ;
P = (rH+rL+rC)/3 ;
p1 = Param("Fast", 1, 1, 100, 1) ;
p2 = Param("Slow", 3, 1, 100, 1) ;
usebpvts = ParamToggle("Use Body Pvts", "No|Yes", 0) ;
isemapvts = ParamToggle("Pvt Type", "H-L|EMA", 1) ;
ismph = H-H ;
ismpl = L-L ;
bph = Max(rO,rC);
bpl = Min(rO,rC);
if (isemapvts)
{
EMA1 = EMA(P, p1) ;
EMA2 = EMA(P, p2) ;
upcross = Cross(EMA1, EMA2) ;
downcross = Cross(EMA2, EMA1) ;
//bph = Max(O,C);
//bpl = Min(O,C);
bi = BarIndex() ;
mphbar = HighestSinceBars(upcross, rH) ;
mplbar = LowestSinceBars(downcross, rL) ;
mphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, mphbar, 0) ;
ismph = mphbi == bi ;
mplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, mplbar, 0) ;
ismpl = mplbi == bi ;
ismph = IIf(downCross AND mphbar == 0, True, ismph) ;
ismpl = IIf(upcross AND mplbar == 0, True, ismpl) ;
bmphbar = HighestSinceBars(upcross, bph) ;
bmplbar = LowestSinceBars(downcross, bpl) ;
bmphbi = ValueWhen(downcross, bi, 0) - ValueWhen(downcross, bmphbar, 0) ;
isbmph = bmphbi == bi ;
bmplbi = ValueWhen(upCross, bi, 0) - ValueWhen(upCross, bmplbar, 0) ;
isbmpl = bmplbi == bi ;
isbmph = IIf(downCross AND bmphbar == 0, True, isbmph) ;
isbmpl = IIf(upcross AND bmplbar == 0, True, isbmpl) ;
}
else
{
isbmph = ismph = rH > Ref(rH, -1) AND rH > Ref(rH, 1) ;
isbmpl = ismpl = rL < Ref(rL, -1) AND rL < Ref(rL, 1) ;
}
showminor = ParamToggle("Show Minor Pvts", "No|Yes", 1) ;
issquare = ParamToggle("Pvt style", "Circle|Square", 0) ;
Clrmph = ParamColor("MPH Color", colorGreen) ;
Clrmpl = ParamColor("MPL Color", colorBrown) ;
pvtmarker = IIf(issquare, shapeSmallSquare, shapeSmallCircle) ;
if (showminor)
{
if (usebpvts)
{
PlotShapes(isbmph*pvtmarker , Clrmph , 0, rH, 12) ;
PlotShapes(isbmpl*pvtmarker , Clrmpl, 0, rL, -12) ;
}
else
{
PlotShapes(ismph*pvtmarker , Clrmph , 0, rH, 12) ;
PlotShapes(ismpl*pvtmarker , Clrmpl, 0, rL, -12) ;
}
}
showminorlvls = ParamToggle("Show Minor Levels", "No|Yes", 1) ;
mph = ValueWhen(ismph, rH) ;
mpl = ValueWhen(ismpl, rL) ;
if (showminorlvls)
{
x = LineArray(0, SelectedValue(mph), (BarCount-1), SelectedValue(mph));
Plot(x, "", colorGold, styleDashed);
x = LineArray(0, SelectedValue(mpl), (BarCount-1), SelectedValue(mpl));
Plot(x, "", colorGold, styleDashed);
}
showminortrend = ParamToggle("Show Minor Trend", "No|Yes", 0) ;
if (showminortrend)
{
// initialize minor levels
mph = ValueWhen(ismph, rH) ;
mpl = ValueWhen(ismpl, rL) ;
mbph = ValueWhen(isbmph, bph) ;
mbpl = ValueWhen(isbmpl, bpl) ;
// minor trend
mut = rH > mph OR (rC > mbph) OR (ismph AND rH > Ref(mph, -1));
mdt = rL < mpl OR (rC < mbpl) OR (ismpl AND rL < Ref(mpl, -1));
mdt = Flip(mdt, mut) ;
mut = Flip(mut, mdt) ;
//mutst = ExRem(mut, mdt) ;
//mdtst = ExRem(mdt, mut) ;
Clr = IIf(mut, colorBlue, colorRed) ;
PlotOHLC(rO,rH,rL,rC, "", Clr, styleCandle|styleNoLabel);
Plot(4, "", Clr, styleArea|styleOwnScale, 0, 100, 0, -1) ;
}
tffactor = Param("TF Factor", 3, 1, 100, 1) ;
showhigher = ParamToggle("Show Higher", "No|Yes", 0) ;
if (showhigher)
{
tfs = tffactor *Interval() ;
TimeFrameSet(tfs) ;
if (isemapvts)
{
Ptf = (H+L+C)/3 ;
EMA1tf = EMA(Ptf, p1) ;
EMA2tf = EMA(Ptf, p2) ;
upcrosstf = Cross(EMA1tf, EMA2tf) ;
downcrosstf = Cross(EMA2tf, EMA1tf) ;
bphtf = Max(O,C) ;
bpltf = Min(O,C) ;
if (usebpvts)
{
Refhtf = bphtf ;
Refltf = bpltf ;
}
else
{
Refhtf = H ;
Refltf = L ;
}
mphbartf = HighestSinceBars(upcrosstf, Refhtf) ;
mplbartf = LowestSinceBars(downcrosstf, Refltf) ;
bitf = BarIndex() ;
mphbitf = ValueWhen(downcrosstf, bitf, 0) - ValueWhen(downcrosstf, mphbartf, 0) ;
ismphtf = mphbitf == bitf ;
mplbitf = ValueWhen(upCrosstf, bitf, 0) - ValueWhen(upCrosstf, mplbartf, 0) ;
ismpltf = mplbitf == bitf ;
ismphtf = IIf(downCrosstf AND mphbartf == 0, True, ismphtf) ;
ismpltf = IIf(upcrosstf AND mplbartf == 0, True, ismpltf) ;
}
else
{
ismphtf = H > Ref(H, -1) AND H > Ref(H, 1) ;
ismpltf = L < Ref(L, -1) AND L < Ref(L, 1) ;
}
if (showminortrend)
{
// initialize minor levels
mphtf = ValueWhen(ismphtf, H) ;
mpltf = ValueWhen(ismpltf, L) ;
mbphtf = ValueWhen(ismphtf, bphtf) ;
mbpltf = ValueWhen(ismpltf, bpltf) ;
// minor trend
muttf = H > mphtf OR (C > mbphtf) OR (ismphtf AND H > Ref(mphtf, -1));
mdttf = L < mpltf OR (C < mbpltf) OR (ismpltf AND L < Ref(mpltf, -1));
mdttf = Flip(mdttf, muttf) ;
muttf = Flip(muttf, mdttf) ;
//mutst = ExRem(mut, mdt) ;
//mdtst = ExRem(mdt, mut) ;
Clrtf = IIf(muttf, colorBlue, colorRed) ;
// PlotOHLC(rO,rH,rL,rC, "", Clr, styleCandle|styleNoLabel);
Clrtfe = TimeFrameExpand(Clrtf, tfs, expandLast) ;
Plot(2, "", Clrtfe, styleArea|styleOwnScale, 0, 100) ;
}
ismphtfe = TimeFrameExpand(ismphtf, tfs, expandFirst) ;
ismpltfe = TimeFrameExpand(ismpltf, tfs, expandFirst) ;
He=TimeFrameExpand(H, tfs, expandFirst) ;
Le=TimeFrameExpand(L, tfs, expandFirst) ;
TimeFrameRestore() ;
ishtfmph = IIf(ismph == ismphtfe, 1, 0) ;
ishtfmpl = IIf(ismpl == ismpltfe, 1, 0) ;
PlotShapes(ismphtfe *shapeSmallSquare, Clrmph , 0, He, 12) ;
PlotShapes(ismpltfe *shapeSmallSquare, Clrmpl, 0, Le, -12) ;
showhtflvls = ParamToggle("Show HTF levels", "No|Yes", 1) ;
Clrhtflvl = colorPaleGreen ;
//Plot(2, "", IIf(ismph , colorBlue, IIf(ismpl, colorRed, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
//Plot(4, "", IIf(ishtfmph , colorBlue, IIf(ishtfmpl , colorRed, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
if (showhtflvls )
{
mphhtf = ValueWhen(ismphtfe , He, 1) ;
mplhtf = ValueWhen(ismpltfe , Le, 1) ;
x = LineArray(0, SelectedValue(mphhtf), (BarCount-1), SelectedValue(mphhtf));
Plot(x, "", Clrhtflvl , styleDashed);
x = LineArray(0, SelectedValue(mplhtf), (BarCount-1), SelectedValue(mplhtf));
Plot(x, "", Clrhtflvl , styleDashed);
}
//Plot(2, "", IIf(ismphtfe , colorRed, IIf(ismpltfe , colorBlue, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
//Plot(4, "", IIf(ismph, colorRed, IIf(ismpl , colorBlue, colorGrey40)), styleArea|styleOwnScale, 0, 100) ;
}
_SECTION_END();