_SECTION_BEGIN("Price");
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 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();
_SECTION_BEGIN("EMA pvts TF");
// 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 protected]
//
debug = ParamToggle("Debug", "No|Yes", 0) ;
ro = ParamField("Open", 0) ;
rh = ParamField("High", 1) ;
rl = ParamField("Low", 2) ;
rc = ParamField("Close", 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) ;
showminor = ParamToggle("Show Minor Pvts", "No|Yes", 1) ;
issquare = ParamToggle("Pvt style", "Circle|Square", 1) ;
Clrmph = ParamColor("MPH Color", colorBlueGrey) ;
Clrmpl = ParamColor("MPL Color", colorOrange) ;
pvtmarker = IIf(issquare, shapeSmallSquare, shapeSmallCircle) ;
showminortrend = ParamToggle("Show Minor Trend", "No|Yes", 1) ;
barht = Param("Bar Ht", 4, 0, 100, 1) ;
showtrendclronbar = ParamToggle("Show Trend on Bar", "No|Yes", 0) ;
tf = Param("TF", 15, 1, 100, 1) ;
showhigher = ParamToggle("Show Higher", "No|Yes", 1) ;
tfs = tf *in1Minute;
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) ;
}
// initialize minor levels
mphtf = ValueWhen(ismphtf, H) ;
mpltf = ValueWhen(ismpltf, L) ;
mbphtf = ValueWhen(ismphtf, bphtf) ;
mbpltf = ValueWhen(ismpltf, bpltf) ;
// minor trend
mphbreak = H > mphtf OR (ismphtf AND H > Ref(mphtf, -1));
mplbreak = L < mpltf OR (ismpltf AND L < Ref(mpltf, -1));
mdttf = Flip(mplbreak , mphbreak ) ;
muttf = Flip(mphbreak , mplbreak) ;
//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, expandFirst) ;
mphbreake = TimeFrameExpand(mphbreak, tfs, expandFirst) ;
mplbreake = TimeFrameExpand(mplbreak, tfs, expandFirst) ;
// Plot(barht, "", Clrtfe, styleArea|styleOwnScale, 0, 100) ;
nlvls = Param("No. of Lvls", 0, 0, 100, 1) ;
showlvls = ParamToggle("Show Lvls", "No|Yes", 0) ;
showatbodies = ParamToggle("Show at Bodies", "No|Yes", 1) ;
showlabel = ParamToggle("Show Label", "No|Yes", 1) ;
Clrhigh = ParamColor("Color High", colorRed) ;
Clrlow = ParamColor("Color Low", colorBlue) ;
styl = 0 ;
if (NOT showlabel)
style |= styleNoLabel ;
if (showlvls)
{
for (i = 1 ; i <= nlvls; i++)
{
Lvlh = ValueWhen(ismphtf, IIf(showatbodies, Max(O,C), H), i) ;
Lvll = ValueWhen(ismpltf, IIf(showatbodies, Min(O,C), L), i) ;
Lvlhe = TimeFrameExpand(Lvlh, tfs, expandFirst) ;
Lvlle = TimeFrameExpand(Lvll, tfs, expandFirst) ;
Plot(IIf(Lvlhe == Ref(Lvlhe, 1), Lvlhe, Null), "", Clrhigh, styleThick|styl |styleNoRescale) ;
Plot(IIf(Lvlle == Ref(Lvlle, 1), Lvlle, Null), "", Clrlow, styleThick|styl |styleNoRescale) ;
}
}
ismphtfe = TimeFrameExpand(ismphtf, tfs, expandFirst) ;
ismpltfe = TimeFrameExpand(ismpltf, tfs, expandFirst) ;
mphtfe = TimeFrameExpand(mphtf, tfs, expandLast) ;
mpltfe = TimeFrameExpand(mpltf, tfs, expandLast) ;
He=TimeFrameExpand(H, tfs, expandFirst) ;
Le=TimeFrameExpand(L, tfs, expandFirst) ;
TimeFrameRestore() ;
//ishtfmph = IIf(ismph == ismphtfe, 1, 0) ;
//ishtfmpl = IIf(ismpl == ismpltfe, 1, 0) ;
showoncrb = ParamToggle("Show On CRB", "No|Yes", 0) ;
Refo = ParamField("CRB Open", 7+0) ;
Refh = ParamField("CRB High", 7+1) ;
Refl = ParamField("CRB Low", 7+2) ;
Refc = ParamField("CRB Close", 7+3) ;
Refbi = ParamField("CRB BI", 7+4) ;
Refcrbbars = ParamField("CRB Bars", 7+5) ;
Refnbars = ParamField("TF Bars", 7+6) ;
Refdt = ParamField("CRB DT", 7+7) ;
if (showoncrb)
{
diffbars = Refnbars -Refcrbbars -1 ;
// convert to crb
Refismphtfe = Ref(ismphtfe, -diffbars) ;
Refismpltfe = Ref(ismpltfe, -diffbars) ;
RefHe = Ref(He, -diffbars) ;
RefLe = Ref(Le, -diffbars) ;
RefClrtfe = Ref(Clrtfe, -diffbars) ;
// RefClre = Ref(Clr, -diffbars) ;
k = 0 ;
for ( i = Crbst ; i < BarCount ; i++)
{
Refbar = Refbi
;
Refismphtfe = ismphtfe[Refbar] ;
Refismpltfe = ismpltfe[Refbar] ;
RefHe = He[Refbar] ;
RefLe = Le[Refbar] ;
RefClrtfe = Clrtfe[Refbar] ;
// RefClre = Clr[Refbar];
k++;
}
}
else
{
Refismphtfe = ismphtfe ;
Refismpltfe = ismpltfe ;
RefHe = He;
RefLe = Le;
RefClrtfe = Clrtfe;
// RefClre = Clre ;
}
markpvts = ParamToggle("Mark Pvts", "No|Yes", 1) ;
showtext = ParamToggle("Show Text", "No|Yes", 1) ;
txtoff = 16 ;
ribLayer = Param("Rib Layer", 0, -5, 5, 1) ;
if (markpvts)
{
PlotShapes(Refismphtfe *pvtmarker , Clrmph , 0, RefHe, 12) ;
PlotShapes(Refismpltfe *pvtmarker , Clrmpl, 0, RefLe, -12) ;
}
if (showminortrend)
Plot(barht, "", RefClrtfe, styleArea|styleOwnScale, 0, 100, 0, ribLayer ) ;
if (showtrendclronbar)
{
// minor trend
hbreak = H > Ref(mphtfe, -1) ;
lbreak = L < Ref(mpltfe, -1) ;
mdt = Flip(lbreak , hbreak ) ;
mut = Flip(hbreak , lbreak) ;
//mutst = ExRem(mut, mdt) ;
//mdtst = ExRem(mdt, mut) ;
Clr = IIf(mut, colorBlue, colorRed) ;
// PlotOHLC(rO,rH,rL,rC, "", Clr, styleCandle|styleNoLabel);
SetBarFillColor(Clr) ;
Plot(C, "", Clr, styleCandle|styleNoLabel, 0,0,0,1) ;
}
ismph = Refismphtfe AND (RefHe == H) ;
ismpl = Refismpltfe AND (RefLe == L) ;
if (showtext)
{
bi = BarIndex() ;
st = LowestVisibleValue(bi) ;
ed = HighestVisibleValue(bi) ;
for (i = st ; i <=ed ; i++)
{
if (ismph)
PlotText(NumToStr(Refhe, 8.1), i-2, Refhe +txtoff-2, colorBlack) ;
if (ismpl)
PlotText(NumToStr(Refle, 8.1), i-2, Refle -txtoff, colorBlack) ;
}
}
showerls = Param("Show ERLs", 0, 0, 10, 1) ;
showderls = Param("Show DERLs", 0, 0, 10, 1) ;
showmoves = ParamToggle("Show Moves", "No|Yes", 0) ;
Connectlast = ParamToggle("Connect Last", "No|Yes", 0) ;
Clrmoveup = ParamColor("Color Move Up", colorBlue) ;
Clrmovedn = ParamColor("Color Move Down", colorRed) ;
if (showerls > 0)
{
Clrerlres = Clrmovedn ;
Clrerlsupp = Clrmoveup ;
mphb = (NOT mphbreake) AND Ref(mphbreake, 1) ;
mplb = (NOT mplbreake) AND Ref(mplbreake, 1) ;
mph = ValueWhen(ismphtfe, H, 1) ;
mpl = ValueWhen(ismpltfe, L, 1) ;
for (i = 1 ; i <= showerls ; i++)
{
res = ValueWhen(mphb, mph, i) ;
supp = ValueWhen(mplb, mpl, i) ;
Plot(res, "", Clrerlres, styleNoLine|styleDots|styleNoTitle|styleNoRescale) ;
Plot(supp, "", Clrerlsupp, styleNoLine|styleDots|styleNoTitle|styleNoRescale) ;
}
}
if (showderls > 0)
{
Clrderlres = Clrmovedn ;
Clrderlsupp = Clrmoveup ;
bi = BarIndex() ;
for (i = 1 ; i <= showderls ; i++)
{
res1 = ValueWhen(ismph, H, i) ;
res1bi = ValueWhen(ismph, bi, i) ;
res2 = ValueWhen(ismph, H, i+1) ;
res2bi = ValueWhen(ismph, bi, i+1) ;
supp1 = ValueWhen(ismpl, L, i) ;
supp1bi = ValueWhen(ismpl, bi, i) ;
supp2 = ValueWhen(ismpl, L, i+1) ;
supp2bi = ValueWhen(ismpl, bi, i+1) ;
derlres = LineArray(SelectedValue(res2bi), SelectedValue(res2), SelectedValue(res1bi), SelectedValue(res1), 1) ;
derlsupp = LineArray(SelectedValue(supp2bi), SelectedValue(supp2), SelectedValue(supp1bi), SelectedValue(supp1), 1) ;
Plot(derlres, "", Clrderlres, styleLine|styleNoTitle|styleNoRescale) ;
Plot(derlsupp, "", Clrderlsupp, styleLine|styleNoTitle|styleNoRescale) ;
}
}
//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) ;
if(showmoves)
{
bi = BarIndex();
edbi = HighestVisibleValue(bi) ;
stbi = LowestVisibleValue(bi) ;
stph = Null ;
stx = 0 ;
edx = 0 ;
edph = Null ;
for (i = stbi; i <= edbi ; i++)
{
if (ismph) // (Refismphtfe AND RefHe == H)
{
stph = edph ;
edph = H ;
stx = edx ;
edx = i ;
}
if (ismpl) // (Refismpltfe AND RefLe == L)
{
stph = edph ;
edph = L ;
stx = edx ;
edx = i ;
}
if (stx!= 0 AND edx !=0)
{
pline = LineArray(stx, stph, edx, edph);
Plot(pline, "", IIf(stph < edph, Clrmoveup, Clrmovedn), styleThick|styleNoLabel) ;
}
}
if (Connectlast)
{
stx = edx ;
edx = BarCount-1 ;
stph = edph ;
edph = C[edx] ;
if (stx!= 0 AND edx !=0)
{
pline = LineArray(stx, stph, edx, edph);
Plot(pline, "", IIf(stph < edph, Clrmoveup, Clrmovedn), styleThick|styleNoLabel) ;
}
}
}
mut = Refclrtfe == colorBlue ;
mdt = NOT mut ;
showzone = ParamToggle("Show Zone", "No|Yes", 0) ;
showasdefarea = ParamToggle("Show as Def Area", "No|Yes", 1) ;
zoneonbodies = ParamToggle("Zone on bodies", "No|Yes", 1) ;
Layerzone = Param("Layer zone", -4, -5, 5, 1) ;
Clrzone = IIf(mut, ParamColor("Zone UT", colorSkyblue), ParamColor("Zone DT", colorRose)) ;
if (showzone)
{
mph = ValueWhen(ismph, H) ;
mpl = ValueWhen(ismpl, L) ;
mbph = ValueWhen(ismph, Max(C, O));
mbpl = ValueWhen(ismpl, Min(C, O)) ;
hbreak = IIf(ismph, H > Ref(mph, -1), H > mph) ;
lbreak = IIf(ismpl, L < Ref(mpl, -1), L < mpl) ;
Hbreak = ExRem(Hbreak, ismph) ;
Lbreak = ExRem(Lbreak, ismpl) ;
up = Flip(Hbreak, Lbreak) ;
mphbreak = Refclrtfe != Ref(Refclrtfe, -1) AND Refclrtfe == colorBlue;
mplbreak = Refclrtfe != Ref(Refclrtfe, -1) AND Refclrtfe == colorRed;
zmph = IIf(zoneonbodies, mbph, mph) ;
zmpl = IIf(zoneonbodies, mbpl, mpl) ;
if (showasdefarea)
{
zoneh = IIf(up, ValueWhen(hbreak, zmph), ValueWhen(lbreak, zmph)) ;
zonel = IIf(up, ValueWhen(hbreak, zmpl), ValueWhen(lbreak, zmpl)) ;
}
else
{
zoneh = ValueWhen(mphbreake OR mplbreake, zmph) ;
zonel = ValueWhen(mphbreake OR mplbreake, zmpl) ;
}
PlotOHLC(zoneh, zoneh, zonel, zonel, "", Clrzone, styleCloud|styleNoLabel|styleNoRescale,0,0,0,Layerzone) ;
}
showtflvls = ParamToggle("Show Lvls", "No|Yes", 1) ;
Clrtflvl = colorPaleGreen ;
if (showtflvls )
{
Hd = ValueWhen(ismphtfe , He, 1) ;
Ld = ValueWhen(ismpltfe , Le, 1) ;
x = LineArray(0, SelectedValue(Hd), (BarCount-1), SelectedValue(Hd));
Plot(x, NumToStr(tfs/in1Minute, 1.0)+"min mph", Clrtflvl , styleDashed|styleNoRescale);
x = LineArray(0, SelectedValue(Ld), (BarCount-1), SelectedValue(Ld));
Plot(x, NumToStr(tfs/in1Minute, 1.0)+"min mpl", Clrtflvl , styleDashed|styleNoRescale);
}
Buy = H > mphtf OR (ismphtf AND H > Ref(mphtf, -1));
Short = L < mpltf OR (ismpltf AND L < Ref(mpltf, -1));
PlotShapes( Buy * shapeUpArrow + Short * shapeDownArrow, IIf( Buy, colorGreen, colorRed ) );
Buy = ExRem( Buy, Short );
Short = ExRem( Short, Buy );
_SECTION_END();