_SECTION_BEGIN("Tops-Bottoms-2-3's");
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=3;
fc=2;
frat=3;
t=H>Ref(HHV(H,frat),-1) AND Ref(HHV(H,frat),frat)<H;
PHighPrice0=ValueWhen(t,H);
b=L<Ref(LLV(L,frat),-1) AND Ref(LLV(L,frat),frat)>L;
PLowPrice0=ValueWhen(b,L);
p=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
d=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
pk=t OR p; tr=b OR d;
px0=ValueWhen(pk,x,0); tx0=ValueWhen(tr,x,0);
px1=ValueWhen(pk,x,1); tx1=ValueWhen(tr,x,1);
px2=ValueWhen(pk,x,2); tx2=ValueWhen(tr,x,2);
px3=ValueWhen(pk,x,3); tx3=ValueWhen(tr,x,3);
ph0=ValueWhen(pk,H,0); tl0=ValueWhen(tr,L,0);
ph1=ValueWhen(pk,H,1); tl1=ValueWhen(tr,L,1);
ph2=ValueWhen(pk,H,2); tl2=ValueWhen(tr,L,2);
ph3=ValueWhen(pk,H,3); tl3=ValueWhen(tr,L,3);
Disp2=ParamToggle("Display 2-3's Labels","Show|Hide",1);
Disp3=ParamToggle("Color Labels Behind 2-3's","Show|Hide",1);
if(Disp3){
PlotShapes(shapeSquare*tr,IIf(Lx-ValueWhen(tr,x)>nbar,colorLime,colorCustom1),0,L,-10);
PlotShapes(shapeSquare*pk,IIf(Lx-ValueWhen(pk,x)>nbar,ColorRGB(255,160,122),colorCustom1),0,H,10);}
dxhm=14; dxlm=10;dxh=3;dxl=2;dyhm=5;
dylm=3;dyh=5;dyl=15;hm=30;lm=30;
function GetVisibleBarCount()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelsToBarX(Pixels)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
fac=pxchartwidth/Pixels;
bar=(lvb-fvb)/fac;
return bar;
}
function GfxConvertPixelToValueY(Pixels)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
fac=pxchartheight/Pixels;
Value=(Maxy-Miny)/fac;
return Value;}
if(Disp2)
{
ll=tr AND tl1<tl2; hl=tr AND tl1>tl2; hh=pk AND ph1>ph2;
lh=pk AND ph1<ph2; dt=pk AND ph1==ph2; db=tr AND tl1==tl2;
miny=Status("axisminy");
maxy=Status("axismaxy");
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
LowMargin=Miny+GfxConvertPixelToValueY(lm);
HighMargin=Maxy-GfxConvertPixelToValueY(hm);
dyllm=GfxConvertPixelToValueY(dylm);
dyhhm=GfxConvertPixelToValueY(dyhm);
dyll=GfxConvertPixelToValueY(dyl);
dyhh=GfxConvertPixelToValueY(dyh);
dxllm=GfxConvertPixelsToBarX(dxlm);
dxhhm=GfxConvertPixelsToBarX(dxhm);
dxll=GfxConvertPixelsToBarX(dxl);
dxhh=GfxConvertPixelsToBarX(dxh);
for(i=0;i<AllVisibleBars;i++)
{
if(ll[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText("Buy",i+fvb+dxll,L[i+fvb]-dyll,colorBlack);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("Buy",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorBlack);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText("Sell",i+fvb+dxhh,H[i+fvb]+dyhh,colorBlack);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("Sell",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorBlack);
}}
_SECTION_END();
_SECTION_BEGIN("Price1");
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();