123 pattern (as part of uncompleted ABCD pattern)
Amibroker AFL LOOKS LIKE |
grid_day = IIf(Day()!=Ref(Day(),-1),1,0);
RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",5,2,50,1);
tf=Param("Time Frame (min)",5,0.01,1440,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",1);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
dispbe123=ParamToggle("Display bearish 123","Off|On",1);
dispbu123=ParamToggle("Display bullish 123","Off|On",1);
dispbeRetraceValues=ParamToggle("Display retrace value (Bearish)","Off|On",1);
dispbuRetraceValues=ParamToggle("Display retrace value (Bullish)","Off|On",1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
entryType=ParamToggle("Entry Type","Regular|Agressive",1);
signalRangeCheck=ParamToggle("Signal Entry Range Limit","Off|On",1);
extendRange=Param("Extended entry range",100,0,500,1);
minRetrace=Param("Retrace Minimum",0.382,0,2,0.01);
maxRetrace=Param("Retrace Maximum",0.88,0,6,0.01);
TimeFrameSet(tfrm);
if(PivotSymmetry)
{
fc=1;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
fc=2;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
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);
if(CleanPivots)
{
tr=IIf((tr==1 AND pk==1) AND px2<tx2 AND Lx!=BarCount-1,False,tr);
pk=IIf((tr==1 AND pk==1) AND px2>tx2 AND Lx!=BarCount-1,False,pk);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
pk=IIf(pk AND ((px0<tx0 AND ph1<ph0) OR (px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
pk=IIf(pk AND (((px0<tx0 AND ph1<ph0) OR px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
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);
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
pk=TimeFrameExpand(pk,tfrm,expandFirst);
pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
pk=pk AND H==pkh;
cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
pk=pk AND cond1;
tr=TimeFrameExpand(tr,tfrm,expandFirst);
trl=TimeFrameExpand(trl,tfrm,expandFirst);
trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
tr=tr AND L==trl;
cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
tr=tr AND cond1;
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);
}
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;
ll_h=IIf(ll,1,0);
hl_h=IIf(hl,2,0);
hh_h=IIf(hh,3,0);
lh_h=IIf(lh,4,0);
dt_h=IIf(dt,5,0);
db_h=IIf(db,6,0);
combi=ll_h+hl_h+lh_h+hh_h+dt_h+db_h;
t0=ValueWhen(combi,combi,0);
t1=ValueWhen(combi,combi,1);
t2=ValueWhen(combi,combi,2);
t3=ValueWhen(combi,combi,3);
t4=ValueWhen(combi,combi,4);
t5=ValueWhen(combi,combi,5);
// bearisch 123 pattern
be123=pk AND t1==4 AND t2==2;
beAx=ValueWhen(be123,tx2);beAy=ValueWhen(be123,tl2);
beBx=ValueWhen(be123,px2);beBy=ValueWhen(be123,ph2);
beCx=ValueWhen(be123,tx1);beCy=ValueWhen(be123,tl1);
beDx=ValueWhen(be123,px1);beDy=ValueWhen(be123,ph1);
beRetrace=(beBy-beCy)/(beBy-beAy);
be123=be123 AND beRetrace>minRetrace AND beRetrace<maxRetrace AND beDy>beCy;
rr=BarsSince(be123)>=0 AND BarsSince(be123)<extendRange;
idx=IIf(rr,xx-ValueWhen(be123,beCx),Null);
if(entryType) aa=(beCy-beAy)/(beCx-beAx);else aa=0;bb=beCy;
aa=ValueWhen(be123,aa);bb=ValueWhen(be123,bb);
beEx=ValueWhen(be123,px1);ii=px1-beCx;beEy=aa*ii+bb;
be123=be123 AND beEy<beDy;
beTrendline=IIf(idx,aa*idx+bb,Null);beValidSignalArea=Flip(be123,Ref(tr,-1));
if(signalRangeCheck) beTrendline=IIf(beValidSignalArea,beTrendline,Null);
Short=Cross(beTrendline,C) AND !IsEmpty(beTrendline);Short=Ref(Short,-1);ShortPrice=O;
Short=ExRem(Short,be123);Sell=0;
// bullish 123 pattern
bu123=tr AND t1==2 AND t2==4;
buAx=ValueWhen(bu123,px2);buAy=ValueWhen(bu123,ph2);
buBx=ValueWhen(bu123,tx2);buBy=ValueWhen(bu123,tl2);
buCx=ValueWhen(bu123,px1);buCy=ValueWhen(bu123,ph1);
buDx=ValueWhen(bu123,tx1);buDy=ValueWhen(bu123,tl1);
buRetrace=(buCy-buBy)/(buAy-buBy);
bu123=bu123 AND buRetrace>minRetrace AND buRetrace<maxRetrace AND buDy<buCy;;
rr=BarsSince(bu123)>=0 AND BarsSince(bu123)<extendRange;
idx=IIf(rr,xx-ValueWhen(bu123,buCx),Null);
if(entryType) aa=(buCy-buAy)/(buCx-buAx);else aa=0;bb=buCy;
aa=ValueWhen(bu123,aa);bb=ValueWhen(bu123,bb);
buEx=ValueWhen(bu123,tx1);ii=tx1-buCx;buEy=aa*ii+bb;
bu123=bu123 AND buEy>buDy;
buTrendline=IIf(idx,aa*idx+bb,Null);buValidSignalArea=Flip(bu123,Ref(pk,-1));
if(signalRangeCheck) buTrendline=IIf(buValidSignalArea,buTrendline,Null);
Buy=Cross(C,buTrendline) AND !IsEmpty(buTrendline);
Buy=Ref(Buy,-1);BuyPrice=O;
Buy=ExRem(Buy,bu123);Cover=0;
GraphXSpace=5;
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorBlue,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorSkyblue,IIf(C<=O,colorGold,colorLightGrey)),64,0,0,0,0);
Plot(pkh,"",colorRed,styleThick,0,0,0,-1);
Plot(trl,"",colorBrightGreen,styleThick,0,0,0,-1);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>nbar*fact,colorBrightGreen,colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>nbar*fact,colorOrange,colorWhite),0,H,10);
qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}
Title =EncodeColor(colorWhite)+ Name() + " | " + Date()+ " | "+ Interval(2)+
"\nNbar: " + nbar +
"\nChart TF: " + tt + tf +
"\nTrend TF: " + tta + tfa;
abcdy_up=27;
abcdy_dn=15;
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;
}
function GfxConvertBarToPixelX(bar)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
return pxchartleft+bar*pxchartwidth/(lvb-fvb+1);
}
function GfxConvertValueToPixelY(value)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
return pxchartbottom-floor(0.5+(Value-Miny)*pxchartheight/(Maxy-Miny));
}
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueY(abcdy_up);
abcdy_dn=GfxConvertPixelToValueY(abcdy_dn);
for(i=0;i<AllVisibleBars;i++)
{
if(ll[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("ll",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hl[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("hl",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(db[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("db",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hh[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("hh",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(lh[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("lh",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(dt[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("dt",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(be123[i+fvb] AND dispbe123)
{
GfxSetOverlayMode(1);
GfxSelectPen(25,1);
GfxSelectSolidBrush(25);
lvix=i+fvb;
GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(25,1,1);
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
GfxSelectPen(25,1,0);
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);
GfxSetTextColor(25);GfxTextOut("1",GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix]))-7,GfxConvertValueToPixelY(beBy[lvix]+1.5*abcdy_up));
GfxSetTextColor(25);GfxTextOut("2",GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix]))-7,GfxConvertValueToPixelY(beCy[lvix]-1.6*abcdy_dn));
GfxSetTextColor(25);GfxTextOut("3",GfxConvertBarToPixelX(i-(beDx[lvix]-beDx[lvix]))-7,GfxConvertValueToPixelY(beDy[lvix]+1.5*abcdy_up));
Plot(LineArray(beCx[lvix],beCy[lvix],beEx[lvix],beEy[lvix],0,True ),"",colorOrange,styleDashed);
Plot(beTrendline,"",colorOrange,styleDots|styleNoLine,0,0,0,0);
PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15));
//PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
if(dispbeRetraceValues)
{
GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkRed);GfxSetTextColor(colorWhite);
GfxTextOut(""+Prec(beRetrace[lvix],2),GfxConvertBarToPixelX(i-(beDx[lvix]-(beAx[lvix]+beCx[lvix])/2)),GfxConvertValueToPixelY((beAy[lvix]+beCy[lvix])/2));
}
}
if(bu123[i+fvb] AND dispbu123)
{
GfxSetOverlayMode(1);
GfxSelectPen(51,1);
GfxSelectSolidBrush(51);
lvix=i+fvb;
GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(51,1,1);
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
GfxSelectPen(51,1,0);
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);
GfxSetTextColor(colorAqua);GfxTextOut("1",GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix]))+3,GfxConvertValueToPixelY(buBy[lvix]-1.6*abcdy_dn));
GfxSetTextColor(colorAqua);GfxTextOut("2",GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix]))+3,GfxConvertValueToPixelY(buCy[lvix]+1.5*abcdy_up));
GfxSetTextColor(colorAqua);GfxTextOut("3",GfxConvertBarToPixelX(i-(buDx[lvix]-buDx[lvix]))+3,GfxConvertValueToPixelY(buDy[lvix]-1.6*abcdy_dn));
Plot(LineArray(buCx[lvix],buCy[lvix],buEx[lvix],buEy[lvix],0,True ),"",colorLime,styleDashed);
Plot(buTrendline,"",colorLime,styleDots|styleNoLine,0,0,0,0);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
//PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
if(dispbuRetraceValues)
{
GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkGreen);GfxSetTextColor(colorWhite);
GfxTextOut(""+Prec(buRetrace[lvix],2),GfxConvertBarToPixelX(i-(buDx[lvix]-(buAx[lvix]+buCx[lvix])/2)),GfxConvertValueToPixelY((buAy[lvix]+buCy[lvix])/2));
}
}
}
RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",5,2,50,1);
tf=Param("Time Frame (min)",5,0.01,1440,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",1);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
dispbe123=ParamToggle("Display bearish 123","Off|On",1);
dispbu123=ParamToggle("Display bullish 123","Off|On",1);
dispbeRetraceValues=ParamToggle("Display retrace value (Bearish)","Off|On",1);
dispbuRetraceValues=ParamToggle("Display retrace value (Bullish)","Off|On",1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
entryType=ParamToggle("Entry Type","Regular|Agressive",1);
signalRangeCheck=ParamToggle("Signal Entry Range Limit","Off|On",1);
extendRange=Param("Extended entry range",100,0,500,1);
minRetrace=Param("Retrace Minimum",0.382,0,2,0.01);
maxRetrace=Param("Retrace Maximum",0.88,0,6,0.01);
TimeFrameSet(tfrm);
if(PivotSymmetry)
{
fc=1;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
else
{
fc=2;
pk=H>Ref(HHV(H,nbar*fc),-1) AND Ref(HHV(H,nbar),nbar)<=H;
tr=L<Ref(LLV(L,nbar*fc),-1) AND Ref(LLV(L,nbar),nbar)>=L;
}
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);
if(CleanPivots)
{
tr=IIf((tr==1 AND pk==1) AND px2<tx2 AND Lx!=BarCount-1,False,tr);
pk=IIf((tr==1 AND pk==1) AND px2>tx2 AND Lx!=BarCount-1,False,pk);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
pk=IIf(pk AND ((px0<tx0 AND ph1<ph0) OR (px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
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);
tr=IIf(tr AND ((tx0<px0 AND tl1>tl0) OR (tx2>px1 AND tl1>tl2) OR (px0==px1 AND tl1>tl0) OR (tl1>tl0 AND px0==tx0)),False,tr);
pk=IIf(pk AND (((px0<tx0 AND ph1<ph0) OR px2>tx1 AND ph1<ph2) OR (tx0==tx1 AND ph1<ph0) OR (ph1<ph0 AND px0==tx0)),False,pk);
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);
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Nz(Max(tfrm/60,Interval()/60)/(Interval()/60));
if(fact==0)fact=1;
Lkbk=Nz(tfrm/Interval());
if(Lkbk>1)
{
pk=TimeFrameExpand(pk,tfrm,expandFirst);
pkh=TimeFrameExpand(pkh,tfrm,expandFirst);
pkhs=IIf(!IsEmpty(pkh),1,0);pkhs=pkhs-Ref(pkhs,-1);
pk=pk AND H==pkh;
cond1=Sum(pk,BarsSince(pkhs==1)+1)==1 AND pk;
pk=pk AND cond1;
tr=TimeFrameExpand(tr,tfrm,expandFirst);
trl=TimeFrameExpand(trl,tfrm,expandFirst);
trls=IIf(!IsEmpty(trl),1,0);trls=trls-Ref(trls,-1);
tr=tr AND L==trl;
cond1=Sum(tr,BarsSince(trls==1)+1)==1 AND tr;
tr=tr AND cond1;
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);
}
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;
ll_h=IIf(ll,1,0);
hl_h=IIf(hl,2,0);
hh_h=IIf(hh,3,0);
lh_h=IIf(lh,4,0);
dt_h=IIf(dt,5,0);
db_h=IIf(db,6,0);
combi=ll_h+hl_h+lh_h+hh_h+dt_h+db_h;
t0=ValueWhen(combi,combi,0);
t1=ValueWhen(combi,combi,1);
t2=ValueWhen(combi,combi,2);
t3=ValueWhen(combi,combi,3);
t4=ValueWhen(combi,combi,4);
t5=ValueWhen(combi,combi,5);
// bearisch 123 pattern
be123=pk AND t1==4 AND t2==2;
beAx=ValueWhen(be123,tx2);beAy=ValueWhen(be123,tl2);
beBx=ValueWhen(be123,px2);beBy=ValueWhen(be123,ph2);
beCx=ValueWhen(be123,tx1);beCy=ValueWhen(be123,tl1);
beDx=ValueWhen(be123,px1);beDy=ValueWhen(be123,ph1);
beRetrace=(beBy-beCy)/(beBy-beAy);
be123=be123 AND beRetrace>minRetrace AND beRetrace<maxRetrace AND beDy>beCy;
rr=BarsSince(be123)>=0 AND BarsSince(be123)<extendRange;
idx=IIf(rr,xx-ValueWhen(be123,beCx),Null);
if(entryType) aa=(beCy-beAy)/(beCx-beAx);else aa=0;bb=beCy;
aa=ValueWhen(be123,aa);bb=ValueWhen(be123,bb);
beEx=ValueWhen(be123,px1);ii=px1-beCx;beEy=aa*ii+bb;
be123=be123 AND beEy<beDy;
beTrendline=IIf(idx,aa*idx+bb,Null);beValidSignalArea=Flip(be123,Ref(tr,-1));
if(signalRangeCheck) beTrendline=IIf(beValidSignalArea,beTrendline,Null);
Short=Cross(beTrendline,C) AND !IsEmpty(beTrendline);Short=Ref(Short,-1);ShortPrice=O;
Short=ExRem(Short,be123);Sell=0;
// bullish 123 pattern
bu123=tr AND t1==2 AND t2==4;
buAx=ValueWhen(bu123,px2);buAy=ValueWhen(bu123,ph2);
buBx=ValueWhen(bu123,tx2);buBy=ValueWhen(bu123,tl2);
buCx=ValueWhen(bu123,px1);buCy=ValueWhen(bu123,ph1);
buDx=ValueWhen(bu123,tx1);buDy=ValueWhen(bu123,tl1);
buRetrace=(buCy-buBy)/(buAy-buBy);
bu123=bu123 AND buRetrace>minRetrace AND buRetrace<maxRetrace AND buDy<buCy;;
rr=BarsSince(bu123)>=0 AND BarsSince(bu123)<extendRange;
idx=IIf(rr,xx-ValueWhen(bu123,buCx),Null);
if(entryType) aa=(buCy-buAy)/(buCx-buAx);else aa=0;bb=buCy;
aa=ValueWhen(bu123,aa);bb=ValueWhen(bu123,bb);
buEx=ValueWhen(bu123,tx1);ii=tx1-buCx;buEy=aa*ii+bb;
bu123=bu123 AND buEy>buDy;
buTrendline=IIf(idx,aa*idx+bb,Null);buValidSignalArea=Flip(bu123,Ref(pk,-1));
if(signalRangeCheck) buTrendline=IIf(buValidSignalArea,buTrendline,Null);
Buy=Cross(C,buTrendline) AND !IsEmpty(buTrendline);
Buy=Ref(Buy,-1);BuyPrice=O;
Buy=ExRem(Buy,bu123);Cover=0;
GraphXSpace=5;
SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,colorBlue,IIf(C<=O,colorRed,colorLightGrey)));
Plot(C,"Price",IIf(C>O,colorSkyblue,IIf(C<=O,colorGold,colorLightGrey)),64,0,0,0,0);
Plot(pkh,"",colorRed,styleThick,0,0,0,-1);
Plot(trl,"",colorBrightGreen,styleThick,0,0,0,-1);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>nbar*fact,colorBrightGreen,colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>nbar*fact,colorOrange,colorWhite),0,H,10);
qq=Interval()/60;
if(qq < 60){tf=" min";tt=qq;}
else if(qq >= 60 AND qq < 1440){tf=" hrs";tt=qq/60;}
else if(qq >= 1440){tf=" days";tt=(qq/60)/24;}
qq=Max(tfrm/60,Interval()/60);
if(qq < 60){tfa=" min";tta=qq;}
else if(qq >= 60 AND qq < 1440){tfa=" hrs";tta=qq/60;}
else if(qq >= 1440){tfa=" days";tta=(qq/60)/24;}
Title =EncodeColor(colorWhite)+ Name() + " | " + Date()+ " | "+ Interval(2)+
"\nNbar: " + nbar +
"\nChart TF: " + tt + tf +
"\nTrend TF: " + tta + tfa;
abcdy_up=27;
abcdy_dn=15;
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;
}
function GfxConvertBarToPixelX(bar)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
return pxchartleft+bar*pxchartwidth/(lvb-fvb+1);
}
function GfxConvertValueToPixelY(value)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
return pxchartbottom-floor(0.5+(Value-Miny)*pxchartheight/(Maxy-Miny));
}
AllVisibleBars=GetVisibleBarCount();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueY(abcdy_up);
abcdy_dn=GfxConvertPixelToValueY(abcdy_dn);
for(i=0;i<AllVisibleBars;i++)
{
if(ll[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("ll",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hl[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("hl",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(db[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("db",
GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn));
}
if(hh[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("hh",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(lh[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("lh",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(dt[i+fvb] AND dispLabels)
{
lvix=i+fvb;GfxSelectFont("Tahoma",8,500); GfxSetBkMode(1);
GfxSetTextColor(colorYellow);GfxTextOut("dt",
GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up));
}
if(be123[i+fvb] AND dispbe123)
{
GfxSetOverlayMode(1);
GfxSelectPen(25,1);
GfxSelectSolidBrush(25);
lvix=i+fvb;
GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(25,1,1);
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(beDy[lvix]));
GfxSelectPen(25,1,0);
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));
GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);
GfxSetTextColor(25);GfxTextOut("1",GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix]))-7,GfxConvertValueToPixelY(beBy[lvix]+1.5*abcdy_up));
GfxSetTextColor(25);GfxTextOut("2",GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix]))-7,GfxConvertValueToPixelY(beCy[lvix]-1.6*abcdy_dn));
GfxSetTextColor(25);GfxTextOut("3",GfxConvertBarToPixelX(i-(beDx[lvix]-beDx[lvix]))-7,GfxConvertValueToPixelY(beDy[lvix]+1.5*abcdy_up));
Plot(LineArray(beCx[lvix],beCy[lvix],beEx[lvix],beEy[lvix],0,True ),"",colorOrange,styleDashed);
Plot(beTrendline,"",colorOrange,styleDots|styleNoLine,0,0,0,0);
PlotShapes(IIf(Short,shapeDownArrow,shapeNone),colorRed,0,H,IIf(Short AND Sell,-30,-15));
//PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),colorWhite,0,ShortPrice,0);
if(dispbeRetraceValues)
{
GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkRed);GfxSetTextColor(colorWhite);
GfxTextOut(""+Prec(beRetrace[lvix],2),GfxConvertBarToPixelX(i-(beDx[lvix]-(beAx[lvix]+beCx[lvix])/2)),GfxConvertValueToPixelY((beAy[lvix]+beCy[lvix])/2));
}
}
if(bu123[i+fvb] AND dispbu123)
{
GfxSetOverlayMode(1);
GfxSelectPen(51,1);
GfxSelectSolidBrush(51);
lvix=i+fvb;
GfxSetBkMode(1);GfxSetOverlayMode(1);GfxSelectPen(51,1,1);
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i),GfxConvertValueToPixelY(buDy[lvix]));
GfxSelectPen(51,1,0);
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxMoveTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]));
GfxLineTo(GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));
GfxSelectFont("Tahoma",10,500);GfxSetBkMode(1);
GfxSetTextColor(colorAqua);GfxTextOut("1",GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix]))+3,GfxConvertValueToPixelY(buBy[lvix]-1.6*abcdy_dn));
GfxSetTextColor(colorAqua);GfxTextOut("2",GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix]))+3,GfxConvertValueToPixelY(buCy[lvix]+1.5*abcdy_up));
GfxSetTextColor(colorAqua);GfxTextOut("3",GfxConvertBarToPixelX(i-(buDx[lvix]-buDx[lvix]))+3,GfxConvertValueToPixelY(buDy[lvix]-1.6*abcdy_dn));
Plot(LineArray(buCx[lvix],buCy[lvix],buEx[lvix],buEy[lvix],0,True ),"",colorLime,styleDashed);
Plot(buTrendline,"",colorLime,styleDots|styleNoLine,0,0,0,0);
PlotShapes(IIf(Buy,shapeUpArrow,shapeNone),colorBrightGreen,0,L,-15);
//PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),colorWhite,0,BuyPrice,0);
if(dispbuRetraceValues)
{
GfxSelectFont("Tahoma",8,650); GfxSetBkMode(2);GfxSetOverlayMode(1);GfxSetBkColor(colorDarkGreen);GfxSetTextColor(colorWhite);
GfxTextOut(""+Prec(buRetrace[lvix],2),GfxConvertBarToPixelX(i-(buDx[lvix]-(buAx[lvix]+buCx[lvix])/2)),GfxConvertValueToPixelY((buAy[lvix]+buCy[lvix])/2));
}
}
}
Greattttt
ReplyDelete