Stock Portfolio Organizer
The ultimate porfolio management solution.
Shares, Margin, CFD's, Futures and Forex
EOD and Realtime
Dividends and Trust Distributions
And Much More ....
WiseTrader Toolbox
#1 Selling Amibroker Plugin featuring:
Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
f2 for Amibroker (AFL)
Copy & Paste Friendly
Back
// 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)",5,1,1440,1);tfrm=in1Minute*tf; CleanPivots=ParamToggle("Force Pivots to Alternate","Off|On",0); 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",colorYellow); GfxSetTextColor(ParamColor("Code Title Color",colorLightGrey)); backGroundColor=ParamColor("Chart Background Color",colorBlack); 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,colorLightGrey))); Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,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)>=rightStrength*fact,ColorRGB(0,100,0),colorWhite),0,L,-10); PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>=rightStrength*fact,ColorRGB(255,0,0),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;} 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 GetVisibleBarCount() { lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar"); return Min(lvb-fvb,BarCount-fvb); } 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 Nz(Value); } function GfxConvertBarToPixelX(bar) { lvb=Status("lastvisiblebar"); fvb=Status("firstvisiblebar"); pxchartleft=Status("pxchartleft"); pxchartwidth=Status("pxchartwidth"); return Nz(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 Nz(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++) { GfxSelectFont("Tahoma",8,500);GfxSetBkMode(1); if(ll[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("LL", GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn)); } if(hl[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("HL", GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn)); } if(db[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("DB", GfxConvertBarToPixelX(i)-3,GfxConvertValueToPixelY(L[lvix]-abcdy_dn)); } if(hh[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("HH", GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up)); } if(lh[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("LH", GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up)); } if(dt[i+fvb] AND dispLabels) { lvix=i+fvb; GfxSetTextColor(LabelColor);GfxTextOut("DT", GfxConvertBarToPixelX(i)-5,GfxConvertValueToPixelY(H[lvix]+abcdy_up)); } }