Hi Guys,
I found Edward Pottasch's AFL on Peaks and Troughs (thanks to him for great work he has provided).
Attaching his code below, but first this question. How to add "line arrays - for horizontal lines" to 'n' number of peaks and troughs (value of 'n' to be set in parameter window). Adding a screenshot for illustration. The lines were drawn manually.
::IMPORTANT::
Lines are drawn from 6 Peaks and 6 Troughs WHICH ARE CLOSEST TO current PRICE.
(this aspect is open for discussion if "closest to current price" should be considered or should it be "Last 6 Peaks and Last 6 Troughs".)
Illustration below:
::About the Code::
AFAIK, the values of "ph0,ph1,ph2" and "tl0,tl1,tl2" represent peaks and troughs respectively. (might be wrong.. i am not good with coding).
Someone please guide here on how to add those "n" line arrays.
I found Edward Pottasch's AFL on Peaks and Troughs (thanks to him for great work he has provided).
Attaching his code below, but first this question. How to add "line arrays - for horizontal lines" to 'n' number of peaks and troughs (value of 'n' to be set in parameter window). Adding a screenshot for illustration. The lines were drawn manually.
::IMPORTANT::
Lines are drawn from 6 Peaks and 6 Troughs WHICH ARE CLOSEST TO current PRICE.
(this aspect is open for discussion if "closest to current price" should be considered or should it be "Last 6 Peaks and Last 6 Troughs".)
Illustration below:
::About the Code::
AFAIK, the values of "ph0,ph1,ph2" and "tl0,tl1,tl2" represent peaks and troughs respectively. (might be wrong.. i am not good with coding).
Someone please guide here on how to add those "n" line arrays.
PHP:
// Fractals
// AFL code by Edward Pottasch, Apr 2013
//RequestTimedRefresh(0.1,True);
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Param("Fractal Pivot Right side Strength",5,2,50,1);
leftStrength=Param("Fractal Pivot Left side Strength",10,2,50,1);
tf=Param("Time Frame (min)",1,1,1440,1);tfrm=in1Minute*tf;
CleanPivots=ParamToggle("Force Pivots to Alternate","Off|On",1);
Cttop=Param("Code Title Top",15,1,250,1);
Ctspac=Param("Code Title Spacing",15,1,250,1);
dispLabels=ParamToggle("Display Labels","Off|On",1);
LabelColor=ParamColor("Label Color",colorBlack);
GfxSetTextColor(ParamColor("Code Title Color",colorDarkGrey));
//backGroundColor=ParamColor("Chart Background Color",GetChartBkColor());
TimeFrameSet(tfrm);
pk=H>Ref(HHV(H,leftStrength),-1) AND Ref(HHV(H,rightStrength),rightStrength)<=H;
tr=L<Ref(LLV(L,leftStrength),-1) AND Ref(LLV(L,rightStrength),rightStrength)>=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)
{
pk=IIf((ph0>=ph1 AND tx0>px0 AND px0!=px1)
OR (ph1<ph2 AND px2>tx1)
OR (ph0>=ph1 AND tx0<px0 AND tx0==tx1 AND px0!=px1)
,False,pk);
tr=IIf((tl0<=tl1 AND px0>tx0 AND tx0!=tx1)
OR (tl1>tl2 AND tx2>px1)
OR (tl0<=tl1 AND px0<tx0 AND px0==px1 AND tx0!=tx1)
,False,tr);
}
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);
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);
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;
//GraphXSpace=5;SetChartBkColor(backGroundColor);SetChartOptions(0,chartShowDates);
//SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorDarkGrey)));
//Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorDarkGrey)),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)>=rightStrength*fact,ColorRGB(0,100,0),colorBlack),0,L,- Param("Offset",10,0,100,0.001));
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>=rightStrength*fact,ColorRGB(255,0,0),colorBlack),0,H,Param("Offset",10,0,100,0.001));
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;}
GfxSetOverlayMode(0);
GfxSetBkMode(1);
GfxSelectFont("Tahoma",11,200);
GfxTextOut("Right Strenght: "+rightStrength,5,Cttop);
GfxTextOut("Left Strenght: "+leftStrength,5,Cttop+Ctspac);
GfxTextOut("Chart Timeframe: "+tt+""+tf,5,Cttop+Ctspac*2);
GfxTextOut("Pivot Timeframe: "+tta+""+tfa,5,Cttop+Ctspac*3);
abcdy_up=27;
abcdy_dn=15;
function GetVisibleBarCountq()
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
return Min(lvb-fvb,BarCount-fvb);
}
function GfxConvertPixelToValueYq(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 Nz(Value);
}
function GfxConvertBarToPixelXq(bar)
{
lvb=Status("lastvisiblebar");
fvb=Status("firstvisiblebar");
pxchartleft=Status("pxchartleft");
pxchartwidth=Status("pxchartwidth");
return Nz(pxchartleft+bar*pxchartwidth/(lvb-fvb+1));
}
function GfxConvertValueToPixelYq(value)
{
local Miny,Maxy,pxchartbottom,pxchartheight;
Miny=Status("axisminy");
Maxy=Status("axismaxy");
pxchartbottom=Status("pxchartbottom");
pxchartheight=Status("pxchartheight");
return Nz(pxchartbottom-floor(0.5+(Value-Miny)*pxchartheight/(Maxy-Miny)));
}
AllVisibleBars=GetVisibleBarCountq();
fvb=Status("firstvisiblebar");
abcdy_up=GfxConvertPixelToValueYq(abcdy_up);
abcdy_dn=GfxConvertPixelToValueYq(abcdy_dn);
for(i=0;i<AllVisibleBars;i++)
{
GfxSelectFont("Tahoma",8,500);GfxSetBkMode(1);
if(ll[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("LL",
GfxConvertBarToPixelXq(i)-3,GfxConvertValueToPixelYq(L[lvix]-abcdy_dn));
}
if(hl[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("HL",
GfxConvertBarToPixelXq(i)-3,GfxConvertValueToPixelYq(L[lvix]-abcdy_dn));
}
if(db[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("DB",
GfxConvertBarToPixelXq(i)-3,GfxConvertValueToPixelYq(L[lvix]-abcdy_dn));
}
if(hh[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("HH",
GfxConvertBarToPixelXq(i)-5,GfxConvertValueToPixelYq(H[lvix]+abcdy_up));
}
if(lh[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("LH",
GfxConvertBarToPixelXq(i)-5,GfxConvertValueToPixelYq(H[lvix]+abcdy_up));
}
if(dt[i+fvb] AND dispLabels)
{
lvix=i+fvb;
GfxSetTextColor(LabelColor);GfxTextOut("DT",
GfxConvertBarToPixelXq(i)-5,GfxConvertValueToPixelYq(H[lvix]+abcdy_up));
}
}