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 ....
For Portfolio Manager Click Here

WiseTrader Toolbox

#1 Selling Amibroker Plugin featuring:

Advanced Adaptive Indicators
Advanced Pattern Exploration
Neural Networks
And Much More ....
Find Out More Here

gfxpolygon example for Amibroker (AFL)

Copy & Paste Friendly
// example code plotting convergence patterns, coded by E.M.Pottasch 2013
RequestTimedRefresh(0.1,True); 
xx=BarIndex();x=xx;Lx=LastValue(x);
rightStrength=Param("Fractal Pivot Right side Strength",5,1,50,1); 
leftStrength=Param("Fractal Pivot Left side Strength",10,1,50,1); 
dispbe=ParamToggle("Display bearish Convergence","Off|On",1);
dispbu=ParamToggle("Display bullish Convergence","Off|On",1);

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

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 Convergence pattern
beConv=pk AND t1==4 AND t2==2;
beAx=ValueWhen(beConv,tx2);beAy=ValueWhen(beConv,tl2);
beBx=ValueWhen(beConv,px2);beBy=ValueWhen(beConv,ph2);
beCx=ValueWhen(beConv,tx1);beCy=ValueWhen(beConv,tl1);
beDx=ValueWhen(beConv,px1);beDy=ValueWhen(beConv,ph1);

// bullish Convergence pattern
buConv=tr AND t1==2 AND t2==4;
buAx=ValueWhen(buConv,px2);buAy=ValueWhen(buConv,ph2);
buBx=ValueWhen(buConv,tx2);buBy=ValueWhen(buConv,tl2);
buCx=ValueWhen(buConv,px1);buCy=ValueWhen(buConv,ph1);
buDx=ValueWhen(buConv,tx1);buDy=ValueWhen(buConv,tl1);

GraphXSpace=5;SetChartBkColor(ColorRGB(0,0,0));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);
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>=rightStrength,ColorRGB(0,100,0),colorWhite),0,L,-10);
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>=rightStrength,ColorRGB(255,0,0),colorWhite),0,H,10);

abcdy_up=27;
abcdy_dn=15;
function GetVisibleBarCount() 
{
	lvb=Status("lastvisiblebar");
	fvb=Status("firstvisiblebar");
	return Min(lvb-fvb,BarCount-fvb);
} 
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");

for(i=0;i<AllVisibleBars;i++) 
{
	if(beConv[i+fvb] AND dispbe)
	{
		GfxSetOverlayMode(1);
		GfxSelectPen(ColorRGB(100,0,0),2); 
		GfxSelectSolidBrush(ColorRGB(20,0,0)); 	
		lvix=i+fvb;	
		GfxPolygon(
		GfxConvertBarToPixelX(i-(beDx[lvix]-beAx[lvix])),GfxConvertValueToPixelY(beAy[lvix]),
		GfxConvertBarToPixelX(i-(beDx[lvix]-beBx[lvix])),GfxConvertValueToPixelY(beBy[lvix]),
		GfxConvertBarToPixelX(i-(beDx[lvix]-beDx[lvix])),GfxConvertValueToPixelY(beDy[lvix]),
		GfxConvertBarToPixelX(i-(beDx[lvix]-beCx[lvix])),GfxConvertValueToPixelY(beCy[lvix]));		
	}
	if(buConv[i+fvb] AND dispbu)
	{
		GfxSetOverlayMode(1);
		GfxSelectPen(ColorRGB(0,100,0),2); 
		GfxSelectSolidBrush(ColorRGB(0,20,0)); 	
		lvix=i+fvb;
		GfxPolygon(
		GfxConvertBarToPixelX(i-(buDx[lvix]-buAx[lvix])),GfxConvertValueToPixelY(buAy[lvix]),
		GfxConvertBarToPixelX(i-(buDx[lvix]-buBx[lvix])),GfxConvertValueToPixelY(buBy[lvix]),
		GfxConvertBarToPixelX(i-(buDx[lvix]-buDx[lvix])),GfxConvertValueToPixelY(buDy[lvix]),
		GfxConvertBarToPixelX(i-(buDx[lvix]-buCx[lvix])),GfxConvertValueToPixelY(buCy[lvix]));  		
	}
}
Back