OK, since it is for charity (but don't send money to charity organization - it will just get lost. Rather give the $80+ to someone near you directly), here is non matrix version of picture of post #2 been sent to @Sumangalam PM box and being in line to the code in 1st post.

Basically you just need two functions...

One for perpenticular bisector's slope and another for perpenticular bisector's intercept.

```
function Gfx_PB_Slope( pointx1, pointy1, pointx2, pointy2 ) {
// perpenticular bisector slope calculation
slope = ( pointy2 - pointy1 ) / ( pointx2 - pointx1 + 1e-9 );
rs = -1 / (slope + 1e-9);
return rs;
}
function Gfx_PB_Intercept( pointx1, pointy1, pointx2, pointy2 ) {
// perpenticular bisector intercept calculation
mid_X = ( pointx1 + pointx2 ) / 2;
mid_Y = ( pointy1 + pointy2 ) / 2;
rs = Gfx_PB_Slope( pointx1, pointy1, pointx2, pointy2 );
rb = mid_Y - rs * mid_X;// intercept
return rb;
}
```

Then the calculation for circle through three points is

```
pxAX = 100;
pxAY = 200;
pxBX = 300;
pxBY = 300;
pxCX = 300;
pxCY = 400;
// perpenticular bisector (A, B) calculation
rsAB = Gfx_PB_Slope( pxAX, pxAY, pxBX, pxBY );// slope
rbAB = Gfx_PB_Intercept( pxAX, pxAY, pxBX, pxBY );// intercept
// perpenticular bisector (B, C) calculations
rsBC = Gfx_PB_Slope( pxBX, pxBY, pxCX, pxCY );// slope
rbBC = Gfx_PB_Intercept(pxBX, pxBY, pxCX, pxCY);// intercept
// Circle's mid point (x,y) & radius calculations
circX = (rbBC - rbAB) / (rsAB - rsBC + 1e-9);
circY = rsBC * circX + rbBC;
rad = sqrt( (pxBX-circX)^2 + (pxBY-circY)^2 );
// draw circle through three points
GfxSelectPen( colorRed, 1, 0 );
GfxSelectStockObject( 5 ); // hollow circle
//GfxSelectSolidBrush( colorDarkRed ); // or filled circle
GfxCircle( circX, circY, rad );
```

Now, here is the **full** code using BeginValue(), EndValue(), SelectedValue() as in post#1.

Just for coding fun since I don't see any trading related value.

But maybe @Sumangalam will tell more about what he/she is after.

**Usage:**

- set some range via Range markers
- then use mouse to single click on some bar

```
// just for fun code of this AmiBroker forum thread
/// @link http://forum.amibroker.com/t/circle-through-three-points/1165/6
slvb = Status( "lastvisiblebar" );
sfvb = Status( "firstvisiblebar" );
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
pxchartleft = Status( "pxchartleft" );
pxchartwidth = Status( "pxchartwidth" );
pxchartbottom = Status( "pxchartbottom" );
pxchartheight = Status( "pxchartheight" );
function GfxBarToPixelX( bar ) {
local bardiff, barnum, relbar, px;
// based on http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/
barnum = slvb - sfvb + 1;
bardiff = bar - sfvb;
relbar = bardiff / barnum;
px = relbar * pxchartwidth + pxchartleft;
return Nz(px);
}
function GfxPriceToPixelY( Value, logscale ) {
local logMiny, logMinMax, pxy;
//based on http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/
if ( logscale ) {
logMiny = log( Miny );
logMinMax = log( Maxy ) - logMiny;
pxy = pxchartbottom - floor( 0.5 + ( log( Value ) - logMiny ) * pxchartheight / logMinMax );
} else {
pxy = pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight / ( Maxy - Miny + 1e-9 ) );
}
return Nz(pxy);
}
function Gfx_PB_Slope( pointx1, pointy1, pointx2, pointy2 ) {
// perpenticular bisector slope calculation
slope = ( pointy2 - pointy1 ) / ( pointx2 - pointx1 + 1e-9 );
rs = -1 / (slope + 1e-9);
return rs;// slope
}
function Gfx_PB_Intercept( pointx1, pointy1, pointx2, pointy2 ) {
// perpenticular bisector intercept calculation
mid_X = ( pointx1 + pointx2 ) / 2;
mid_Y = ( pointy1 + pointy2 ) / 2;
rs = Gfx_PB_Slope( pointx1, pointy1, pointx2, pointy2 );
rb = mid_Y - rs * mid_X;// intercept
return rb;
}
array = H;
bi = BarIndex();
_log = 0;
if( SelectedValue( bi ) < BeginValue( bi ) ) {
// if point B_X becomes smaller than point A_X
Point_A_X = SelectedValue( bi );
Point_A_Y = SelectedValue( array );
Point_B_X = BeginValue( bi );
Point_B_Y = BeginValue( array );
Point_C_X = EndValue( bi );
Point_C_Y = EndValue( array );
} else if( SelectedValue( bi ) > EndValue( bi ) ) {
// if point B_X becomes larger than point C_X
Point_A_X = BeginValue( bi );
Point_A_Y = BeginValue( array );
Point_B_X = EndValue( bi );
Point_B_Y = EndValue( array );
Point_C_X = SelectedValue( bi );
Point_C_Y = SelectedValue( array );
} else {
Point_A_X = BeginValue( bi );
Point_A_Y = BeginValue( array );
Point_B_X = SelectedValue( bi );
Point_B_Y = SelectedValue( array );
Point_C_X = EndValue( bi );
Point_C_Y = EndValue( array );
}
pxAX = GfxBarToPixelX( Point_A_X );
pxAY = GfxPriceToPixelY( Point_A_Y, _log );
pxBX = GfxBarToPixelX( Point_B_X );
pxBY = GfxPriceToPixelY( Point_B_Y, _log );
pxCX = GfxBarToPixelX( Point_C_X );
pxCY = GfxPriceToPixelY( Point_C_Y, _log );
// perpenticular bisector (A, B) calculation
midAB_X = (pxAX + pxBX) / 2;
midAB_Y = (pxAY + pxBY) / 2;
rsAB = Gfx_PB_Slope( pxAX, pxAY, pxBX, pxBY );// slope
rbAB = Gfx_PB_Intercept( pxAX, pxAY, pxBX, pxBY );// intercept
// perpenticular bisector (B, C) calculations
midBC_X = (pxBX + pxCX) / 2;
midBC_Y = (pxBY + pxCY) / 2;
rsBC = Gfx_PB_Slope( pxBX, pxBY, pxCX, pxCY );// slope
rbBC = Gfx_PB_Intercept(pxBX, pxBY, pxCX, pxCY);// intercept
// Circle's mid point & radius calculations
circX = (rbBC - rbAB) / (rsAB-rsBC + 1e-9);
circY = rsBC * circX + rbBC;
rad = sqrt( (pxBX-circX)^2 + (pxBY-circY)^2 );
// ########################################################################
// ###################### GFX DRAWING PART ################################
// ########################################################################
Plot( C, "Price", colorDefault, styleCandle );
GfxSetZOrder( 0 );
GfxSelectFont( "ARIAL", 12 );
GfxSetTextAlign( 6 | 0 );
GfxSetBkMode( 2 );
GfxSelectPen( colorRed, 1, 0 );
GfxSelectSolidBrush( colorDarkRed );
// Draw Line from A to B
GfxMoveTo( pxAX, pxAY );
GfxLineTo( pxBX, pxBY );
// Draw Line from B to C
GfxMoveTo( pxBX, pxBY );
GfxLineTo( pxCX, pxCY );
// draw points A, B, C
GfxCircle( pxAX, pxAY, 3 );
GfxCircle( pxBX, pxBY, 3 );
GfxCircle( pxCX, pxCY, 3 );
GfxTextOut( "A", pxAX, pxAY + 10 );
GfxTextOut( "B", pxBX, pxBY + 10 );
GfxTextOut( "C", pxCX, pxCY + 10 );
GfxSelectPen( colorGold, 1, 0 );
// Draw perpenticular bisector lines
GfxMoveTo( midAB_X, midAB_Y );
GfxLineTo( circX, circY );
GfxMoveTo( midBC_X, midBC_Y );
GfxLineTo( circX, circY );
// AB mid point
GfxCircle( midAB_X, midAB_Y, 3 );
// BC mid point
GfxCircle( midBC_X, midBC_Y, 3 );
// draw circle's mid point
GfxCircle( circX, circY, 3 );
// draw circle through three points
GfxSetZOrder( -1 );
GfxSelectPen( colorRed, 1, 0 );
GfxSelectStockObject( 5 ); // hollow circle
//GfxSelectSolidBrush( colorDarkRed ); // or filled circle
GfxCircle( circX, circY, rad );
```