Edward Pottasch AFL ? bcoz its keep changing " entry levels"??

pareshR

Well-Known Member
#1
Hello

members would you help me how to use Edward Pottasch AFL ? bcoz its keep changing " entry levels"?? so how to get trades?
which time frame and "N Pivot Bars"?

thx
paresh


www.wisestocktrader.com/indicators/2824-trendline-multiple-timeframe


_SECTION_BEGIN("Trendlines Multitimeframe");
// Amibroker AFL code by Edward Pottasch, 6/8/2011
// Using fractals to create automatic trendlines
// Using option to show multiple timeframes
Version(5.21);
xx=BarIndex();x=xx;Lx=LastValue(x);
nbar=Param("N Pivot Bars",3,2,50,1);
tf=Param("Time Frame (min)",5,1,100000,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Use Clean Pivots","Off|On",0);
PivotSymmetry=ParamToggle("Use Symmetric Pivots","Off|On",0);
tld=ParamToggle("All trendlines","Show|Hide",1);
showSignals=ParamToggle("Display signals","Off|On",0);

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);
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);
if (CleanPivots)
{
tr=IIf(pk AND tr AND ph1>ph2 AND tl1>tl2,False,tr);
pk=IIf(pk AND tr AND ph1<ph2 AND tl1<tl2,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);
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);

pk=IIf(pk AND px1>tx1 AND ph1<tl1,False,pk);
tr=IIf(tr AND tx1>px1 AND tl1>ph1,False,tr);
pk=IIf(pk AND px0<tx0 AND ph0>ph1,False,pk);
tr=IIf(tr AND px0>tx0 AND tl0<tl1,False,tr);
pk=IIf(pk AND px2>tx1 AND ph1<=ph2,False,pk);
tr=IIf(tr AND tx2>px1 AND tl1>=tl2,False,tr);
pk=IIf(pk AND px0>px1 AND px1>tx1 AND px1>tx0 AND ph0>ph1,False,pk);
tr=IIf(tr AND tx0>tx1 AND tx1>px1 AND tx1>px0 AND tl0<tl1,False,tr);

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);
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);

pk=IIf(pk AND px1>tx1 AND ph1<tl1,False,pk);
tr=IIf(tr AND tx1>px1 AND tl1>ph1,False,tr);
pk=IIf(pk AND px0<tx0 AND ph0>ph1,False,pk);
tr=IIf(tr AND px0>tx0 AND tl0<tl1,False,tr);
pk=IIf(pk AND px2>tx1 AND ph1<=ph2,False,pk);
tr=IIf(tr AND tx2>px1 AND tl1>=tl2,False,tr);
pk=IIf(pk AND px0>px1 AND px1>tx1 AND px1>tx0 AND ph0>ph1,False,pk);
tr=IIf(tr AND tx0>tx1 AND tx1>px1 AND tx1>px0 AND tl0<tl1,False,tr);

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);
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);

pk=IIf(pk AND px1>tx1 AND px2>tx1 AND ph1<ph2,False,pk);
tr=IIf(tr AND tx1>px1 AND tx2>px1 AND tl1>tl2,False,tr);
}
pkh=IIf(pk,H,Null);
trl=IIf(tr,L,Null);
TimeFrameRestore();
fact=Max(tfrm/60,Interval()/60)/(Interval()/60);
Lkbk=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);
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);
}
y0=ValueWhen(tr,trl,0);
y1=ValueWhen(tr,trl,1);
y2=ValueWhen(tr,trl,2);
y3=ValueWhen(tr,trl,3);
x0=ValueWhen(tr,xx,0);
x1=ValueWhen(tr,xx,1);
x2=ValueWhen(tr,xx,2);
x3=ValueWhen(tr,xx,3);
aa=(Y0-Y1)/(X0-X1);
ls1=aa*(xx-X1)+Y1;
dls1=ls1-Ref(ls1,-1);
aa=(Y1-Y2)/(X1-X2);
ls2=aa*(xx-X1)+Y1;
dls2=ls2-Ref(ls2,-1);
dls2=IIf(tr,Ref(dls1,-1),dls2);
aa=(Y2-Y3)/(X2-X3);
ls3=aa*(xx-X2)+Y2;
dls3=ls3-Ref(ls3,-1);
dls3=IIf(tr,Ref(dls2,-1),dls3);
y0=ValueWhen(pk,pkh,0);
y1=ValueWhen(pk,pkh,1);
y2=ValueWhen(pk,pkh,2);
y3=ValueWhen(pk,pkh,3);
x0=ValueWhen(pk,xx,0);
x1=ValueWhen(pk,xx,1);
x2=ValueWhen(pk,xx,2);
x3=ValueWhen(pk,xx,3);
aa=(Y0-Y1)/(X0-X1);
hs1=aa*(xx-X1)+Y1;
dhs1=hs1-Ref(hs1,-1);
aa=(Y1-Y2)/(X1-X2);
hs2=aa*(xx-X1)+Y1;
dhs2=hs2-Ref(hs2,-1);
dhs2=IIf(pk,Ref(dhs1,-1),dhs2);
aa=(Y2-Y3)/(X2-X3);
hs3=aa*(xx-X2)+Y2;
dhs3=hs3-Ref(hs3,-1);
dhs3=IIf(pk,Ref(dhs2,-1),dhs3);
if (tld)
{
dd=0.0;
Vh=dd*(ValueWhen(pk,C)-ValueWhen(pk,Ref(C,-1)))/ValueWhen(pk,C);
Vl=dd*(ValueWhen(tr,C)-ValueWhen(tr,Ref(C,-1)))/ValueWhen(tr,C);
ls1=IIf(dls1>=Vl,ls1,Null);
ls2=IIf(dls2>=Vl,ls2,Null);
ls3=IIf(dls3>=Vl,ls3,Null);
hs1=IIf(dhs1<=Vh,hs1,Null);
hs2=IIf(dhs2<=Vh,hs2,Null);
hs3=IIf(dhs3<=Vh,hs3,Null);
}
ls2a=IIf(BarsSince(tr)<=nbar*fact,ls2,Null);
ls2b=IIf(BarsSince(tr)>nbar*fact,ls2,Null);
ls3=IIf(BarsSince(tr)<=nbar*fact,ls3,Null);
hs2a=IIf(BarsSince(pk)<=nbar*fact,hs2,Null);
hs2b=IIf(BarsSince(pk)>nbar*fact,hs2,Null);
hs3=IIf(BarsSince(pk)<=nbar*fact,hs3,Null);
_SECTION_END();

_SECTION_BEGIN("Chart Colors");
SetChartBkColor(ParamColor("Background Color",ColorRGB(0,0,0)));
SetChartOptions(0,chartShowDates);
SetBarFillColor(IIf(C>O,ParamColor("Candle UP Color", colorGreen),IIf(C<=O,ParamColor("Candle Down Color", colorRed),colorLightGrey)));
Plot(C,"Price",IIf(C>O,ParamColor("Wick UP Color", colorDarkGreen),IIf(C<=O,ParamColor("Wick Down Color", colorDarkRed),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,ColorRGB(0,100,0),colorW hite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>nbar*fact,ColorRGB(255,0,0),colorW hite),0,H,10);
Plot(ls1,"\nLower Trendline",colorBrightGreen,styleLine|styleNoResca le,0,0,0,-1);
Plot(ls2a,"",colorLightGrey,styleNoLine|styleDots| styleThick|styleNoRescale,0,0,0,-1);
Plot(ls2b,"",colorDarkGreen,styleNoLine|styleDots| styleThick|styleNoRescale,0,0,0,-1);
Plot(ls3,"",colorDarkGreen,styleNoLine|styleDots|s tyleThick|styleNoRescale,0,0,0,-1);
Plot(hs1,"\nUpper Trendline",colorRed,styleLine|styleNoRescale,0,0,0 ,-1);
Plot(hs2a,"",colorLightGrey,styleNoLine|styleDots| styleThick|styleNoRescale,0,0,0,-1);
Plot(hs2b,"",colorOrange,styleNoLine|styleDots|sty leThick|styleNoRescale,0,0,0,-1);
Plot(hs3,"",colorOrange,styleNoLine|styleDots|styl eThick|styleNoRescale,0,0,0,-1);
_SECTION_END();

if(showSignals)
{
Buy=( (!IsEmpty(Ref(hs2b,-1)) AND Ref(C<hs2b,-1)) AND (!IsEmpty(hs2b) AND C>hs2b) )
OR ( (!IsEmpty(Ref(hs3,-1)) AND Ref(C<hs3,-1)) AND (!IsEmpty(hs3) AND C>hs3) )
OR ( (!IsEmpty(Ref(hs2b,-1)) AND Ref(C<hs2b,-1)) AND (!IsEmpty(hs3) AND C>hs3) );
Buy=ExRem(Buy,tr OR pk);
BuyPrice=C;

Short=( (!IsEmpty(Ref(ls2b,-1)) AND Ref(C>ls2b,-1)) AND (!IsEmpty(ls2b) AND C<ls2b) )
OR ( (!IsEmpty(Ref(ls3,-1)) AND Ref(C>ls3,-1)) AND (!IsEmpty(ls3) AND C<ls3) )
OR ( (!IsEmpty(Ref(ls2b,-1)) AND Ref(C>ls2b,-1)) AND (!IsEmpty(ls3) AND C<ls3) );
Short=ExRem(Short,tr OR pk);
ShortPrice=C;
PlotShapes(IIf(Buy,shapeSmallUpTriangle,shapeNone) ,colorGreen,0,L,-15);
PlotShapes(IIf(Buy,shapeSmallCircle,shapeNone),col orWhite,0,BuyPrice,0);
PlotShapes(IIf(Short,shapeSmallDownTriangle,shapeN one),colorRed,0,H,-15);
PlotShapes(IIf(Short,shapeSmallCircle,shapeNone),c olorWhite,0,ShortPrice,0);
}

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 = Name() +
"\nNbar: " + nbar +
"\nChart TF: " + tt + tf +
"\nTrend TF: " + tta + tfa;

_SECTION_BEGIN("Label");
disp=ParamToggle("Display labels","Off|On",1);
dxhm=Param("Shift X Highs (Margin)",14,-100,100,1);
dxlm=Param("Shift X Lows (Margin)",10,-100,100,1);
dxh=Param("Shift X Highs",0,-100,100,1);
dxl=Param("Shift X Lows",0,-100,100,1);
dyhm=Param("Shift Y Highs (Margin)",5,-100,100,1);
dylm=Param("Shift Y Lows (Margin)",3,-100,100,1);
dyh=Param("Shift Y Highs",18,-100,100,1);
dyl=Param("Shift Y Lows",29,-100,100,1);
hm=Param("Marging High",30,-100,100,1);
lm=Param("Margin Low",30,-100,100,1);

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(disp)
{
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;

PlotShapes(shapeHollowCircle*lh,ColorRGB(255,193,1 93),0,H,10);
PlotShapes(shapeHollowCircle*hl,ColorRGB(202,255,1 12),0,L,-10);

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("LL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(ll[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("LL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(hl[i+fvb] AND L[i+fvb]>LowMargin) PlotText("HL",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(hl[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("HL",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(db[i+fvb] AND L[i+fvb]>LowMargin) PlotText("DB",i+fvb+dxll,L[i+fvb]-dyll,colorWhite,colorBlack);
if(db[i+fvb] AND L[i+fvb]<=LowMargin) PlotText("DB",i+fvb+dxll+dxllm,L[i+fvb]-dyllm,colorWhite,colorBlack);
if(hh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("HH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(hh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("HH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorBlack);
if(lh[i+fvb] AND H[i+fvb]<HighMargin) PlotText("LH",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(lh[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("LH",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorBlack);
if(dt[i+fvb] AND H[i+fvb]<HighMargin) PlotText("DT",i+fvb+dxhh,H[i+fvb]+dyhh,colorWhite,colorBlack);
if(dt[i+fvb] AND H[i+fvb]>=HighMargin) PlotText("DT",i+fvb+dxhh+dxhhm,H[i+fvb]+dyhhm,colorWhite,colorBlack);
}
Plot(tr,"",ColorRGB(0,100,0),styleHistogram|styleD ashed|styleOwnScale|styleNoLabel,0,1,0,0);
Plot(pk,"",ColorRGB(100,0,0),styleHistogram|styleD ashed|styleOwnScale|styleNoLabel,0,1,0,0);

}
_SECTION_END();
 

casoni

Well-Known Member
#2
Hello ,

keep " Display signals " = 1 [change from parameter window] ,

this will display BUY / SHORT SIGNALS , and this signals dosen't repaint
because signal will fire only after 2 nd peak / trough is confirmed

you will get signal after grey dotted line ends , tand darkgreen or orange color dotted line begins [ that is the confirmation , that peak / trough has established]

check on Bar repaly
you will understand , i am very poor in explaining

Thank you
 

bunti_k23

Well-Known Member
#4
it keep son changing because you are an idiot LOL. No seriously I just think people should try a little when they get code at no cost. Just try to understand it before you smear my name
haha too sarcastic:D
 
#5
I'm sorry I lashed out. I just posted some code elsewhere and all I get is "not working" so I got a bit frustrated. This code posted in this thread is old code and has some unnecessary code in there.

I have posted code that use pivots and pivots will change until they are confirmed. So the pivot always is known after the fact. These pivots I mostly used to identify patterns.

I posted some code here where maybe it is more clear:

http://wisestocktrader.com/indicators/5272-convergence-pattern-based-on-new-atr-pivots

if you do a playback then you will also see patterns form and change their shape while they are forming. The shape is given a grayish color when it is still in the process of development. Once it is confirmed it will turn red or green and will no longer change.
 
#6
Sir,

People talk highly of you & your techniques.

Is there any regular location where your old and new/updated ideas, codes, posts etc may be found.

Thanx
 

mastermind007

Well-Known Member
#7
#8
Hi

There was another thread started by me sometime ago about Edward's AFLs.

Coding ability of Edward is superb however I wish there was a tutorial with each of his AFL on how exactly to use it.

http://www.traderji.com/amibroker/103087-edward-pottash-afls.html

these fractal type pivots are basically straightforward until you "clean" or try to alternate them. Meaning that an alternating (or clean) set of fractal pivots has a peak - trough - peak - trough - peak etc.

I made some code that does this good but will post only when I got my mind made up when a pivot is "valid" and will not suddenly disappear.

If you playback the code made by Edakad (that has to be 2009 or so), see: http://www.wisestocktrader.com/indicatorpasties/25-harmonic-pattern-1-1-1

then you also see that at the end of the array pivots plotted in the chart suddenly disappear. Not saying his patterns are wrong since it seems his patterns ignore these disappearing pivot points.

But this is why I turned to ATR pivots which always alternate. But I will think a bit more how to alternate (=> clean) fractal type pivots.
 

mastermind007

Well-Known Member
#9
these fractal type pivots are basically straightforward until you "clean" or try to alternate them. Meaning that an alternating (or clean) set of fractal pivots has a peak - trough - peak - trough - peak etc.

I made some code that does this good but will post only when I got my mind made up when a pivot is "valid" and will not suddenly disappear.

If you playback the code made by Edakad (that has to be 2009 or so), see: http://www.wisestocktrader.com/indicatorpasties/25-harmonic-pattern-1-1-1

then you also see that at the end of the array pivots plotted in the chart suddenly disappear. Not saying his patterns are wrong since it seems his patterns ignore these disappearing pivot points.

But this is why I turned to ATR pivots which always alternate. But I will think a bit more how to alternate (=> clean) fractal type pivots.
Are you Edward Pottash? WOW!!!

Glad to know that you are here in this forum. :clap:

In one AFL hat relies on Darvas box pivots (2 lower on each side), I have changed code to raise signal two candles late because I do not want vanishing signals. Results are not that impressive so it is one of those damned-if-you-do-and-damned-if-you-don't stuff

I do somewhat understand rationale behind forward reference.
 
#10
Are you Edward Pottash? WOW!!!

Glad to know that you are here in this forum. :clap:

In one AFL hat relies on Darvas box pivots (2 lower on each side), I have changed code to raise signal two candles late because I do not want vanishing signals. Results are not that impressive so it is one of those damned-if-you-do-and-damned-if-you-don't stuff

I do somewhat understand rationale behind forward reference.
hi mastermind, thanks but i am just a simple coder like the most of us. With respect to Darvas boxes. I made some code on this few year back. Are you referring to this code?


I didn't do any work on these fractal pivots although my cleaning seems good. It is just that when you "clean" the pivots it is probably impossible to say when they are valid and will not repaint.

below the code for the cleaning. See parameter window. Maybe someone else has a clear mind to say when a pivot is "valid" and can not suddenly disappear while new data comes in. New data can behave pretty odd at times and peak and troughs follow in close sequence only to disappear when you use clean

cose below, see also: http://wisestocktrader.com/indicatorpasties/1738-clean-pivots

Version( 6.0 );

x = BarIndex();
fvb = FirstVisibleValue( x );
lvb = LastVisibleValue( x );
rightStrength = Param( "Fractal Pivot Right side Strength", 5, 0, 50, 1 );
leftStrength = Param( "Fractal Pivot Left side Strength", 10, 0, 50, 1 );
tf = Param( "Time Frame (min)", 5, 1, 10080, 1 );
tog1 = ParamToggle( "Alternate Pivots", "No|Yes", 1 );// clean pivots

tfrm = in1Minute * tf;
fact = Nz( Max( tfrm / 60, Interval() / 60 ) / ( Interval() / 60 ) );

if( fact == 0 )
fact = 1;

pk = tr = px0 = px1 = px2 = tx0 = tx1 = tx2 = ph0 = ph1 = ph2 = tl0 = tl1 = tl2 = ll = hl = hh = lh = dt = db = 0;
pkn = trn = pxn0 = pxn1 = pxn1 = txn0 = txn1 = txn2 = phn0 = phn1 = phn2 = tln0 = tln1 = tln2 = 0;

function calculateMainPivots()
{
pk = H > Ref( HHV( H, leftStrength * fact ), -1 ) AND Ref( HHV( H, rightStrength * fact ), rightStrength * fact ) <= H;
tr = L < Ref( LLV( L, leftStrength * fact ), -1 ) AND Ref( LLV( L, rightStrength * fact ), rightStrength * fact ) >= L;

if( tog1 )
{
pkw = pk;
trw = tr;
pk = pkw AND H == HighestSince( trw, H );
tr = trw AND L == LowestSince( pkw, L );

pkw = pk;
trw = tr;
tr = ExRem( Reverse( trw ), Reverse( pkw ) );
pk = ExRem( Reverse( pkw ), Reverse( trw ) );

tr = Reverse( tr );
pk = Reverse( pk );
}

for( i = 0; i < 3; i++ )
{
VarSet( "px" + i, ValueWhen( pk, x, i ) );
VarSet( "tx" + i, ValueWhen( tr, x, i ) );
VarSet( "ph" + i, ValueWhen( pk, H, i ) );
VarSet( "tl" + i, ValueWhen( tr, L, i ) );

VarSet( "pxdis" + i, lvb - ValueWhen( pk, x, i ) );
VarSet( "txdis" + i, lvb - ValueWhen( tr, x, i ) );
}

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;
}

function calculateWorkingPivots()
{
pkn = H > Ref( HHV( H, ( leftStrength + 0 ) * fact ), -1 );
trn = L < Ref( LLV( L, ( leftStrength + 0 ) * fact ), -1 );

for( i = 0; i < 3; i++ )
{
VarSet( "pxn" + i, ValueWhen( pkn, x, i ) );
VarSet( "txn" + i, ValueWhen( trn, x, i ) );
VarSet( "phn" + i, ValueWhen( pkn, H, i ) );
VarSet( "tln" + i, ValueWhen( trn, L, i ) );
}
}

GraphXSpace = 5;
SetChartBkColor( colorBlack );
SetChartOptions( 1, chartShowDates, chartGridMiddle, 0, 0, 0 );
SetBarFillColor( IIf( C > O, ColorRGB( 0, 75, 0 ), IIf( C <= O, ColorRGB( 75, 0, 0 ), colorLightGrey ) ) );
Plot( C, "", IIf( C > O, ColorRGB( 0, 255, 0 ), IIf( C <= O, ColorRGB( 255, 0, 0 ), colorLightGrey ) ), 64, Null, Null, 0, 0, 1 );

function drawPivotLabels()
{
sz = 5;

for( i = lvb; i > fvb; i-- )
{
{
if( ll ) PlotTextSetFont( "LL", "Arial Black", sz, i, L, colorGreen, colorDefault, -25 );

if( hl ) PlotTextSetFont( "HL", "Arial Black", sz, i, L, colorGreen, colorDefault, -25 );

if( db ) PlotTextSetFont( "DB", "Arial Black", sz, i, L, colorLightBlue, colorDefault, -25 );

if( hh ) PlotTextSetFont( "HH", "Arial Black", sz, i, H, colorRed, colorDefault, 20 );

if( lh ) PlotTextSetFont( "LH", "Arial Black", sz, i, H, colorRed, colorDefault, 20 );

if( dt ) PlotTextSetFont( "DT", "Arial Black", sz, i, H, colorOrange, colorDefault, 20 );
}
}
}

calculateMainPivots();
calculateWorkingPivots();
drawPivotLabels();

PlotShapes( shapeSmallCircle*trn, ColorRGB( 0, 30, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle*pkn, ColorRGB( 50, 0, 0 ), 0, H, 10 );

if( !tog1 )// cleanpivots turned off
{
PlotShapes( shapeSmallCircle * tr, IIf( txdis1 > rightStrength * fact, ColorRGB( 0, 255, 0 ), colorWhite ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, IIf( pxdis1 > rightStrength * fact, ColorRGB( 255, 0, 0 ), colorWhite ), 0, H, 10 );
}
else // cleanpivots turned on
{
// => this part not finished, validation still needs to be adressed
PlotShapes( shapeSmallCircle * tr, ColorRGB( 0, 255, 0 ), 0, L, -10 );
PlotShapes( shapeSmallCircle * pk, ColorRGB( 255, 0, 0 ), 0, H, 10 );
}

Title = Name() +
" | " + Now( 2 );
 

Similar threads

Zerodha – Open Paperless Account

Open online account with Zerodha. Free delivery trading and Max Rs 20 for Intraday, F&O, Currency and Commodity Trading. Intraday High leverage with MIS, CO and BO.

Name:Phone:
Email:City:
State:
Are you a day trader?