Hello,
I need to calculate distance between High at BeginValue(BarIndex()) and Low at EndValue(BarIndex()).
While I was trying to figure out how to approach this objective - I thought of finding pixel distance between the two points.
However, I could not figure out how to find “Pixel X Y of High at BeginValue(BarIndex())” or “Pixel X Y of Low at EndValue(BarIndex())”.
Will appreciate very much any guidance about this.
Regards
Sanjiv Bansal
As I experiment further on the topic, I tried Example 4 at" https://www.amibroker.com/guide/h_lowlevelgfx.html " as a starting point to understand the things.
However, I am getting Warning 505. Divison by zero in the following line of the example code:
y = 5 + ( C[ i + fvb ] - Miny ) * ( pxheight - 10 )/ ( Maxy - Miny );
Environment: Amibroker 6.21 Pro 32Bit (Win 10 Pro 64Bit)
Regards
Sanjiv Bansal
PS: I could not edit my original post, hence had to send this update as a reply to by own post. (Will learn more about the Forum now.)
Hello,
I seem to have got lucky - while reading the help file for STATUS function, readymade samples for conversion to PixelX and PixelY were found. The following solved what I was looking for:
Up_Dn = iif( EndValue( C ) > BeginValue( C ), 1, -1 );
HL_Beg = BeginValue( IIf( Up_Dn == 1, L, H ) );
HL_End = EndValue( IIf( Up_Dn == 1, H, L ) );
_SECTION_BEGIN("GfxOverlaySampleNew");
function GfxConvertBarToPixelX( bar )
{
lvb = Status("lastvisiblebar");
fvb = Status("firstvisiblebar");
pxchartleft = Status("pxchartleft");
pxchartwidth = Status("pxchartwidth");
return 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 pxchartbottom - floor( 0.5 + ( Value - Miny ) * pxchartheight/ ( Maxy - Miny ) );
}
Plot( C, "Close", colorLime, styleBar, Null, Null, 0, 2, 1 );
bi = BarIndex();
EndVal_BI = endValue( bi ) - FirstVisibleValue(bi);
BegVal_BI = beginValue( bi ) - FirstVisibleValue(bi);
X_Length = abs(GfxConvertBarToPixelX(EndVal_BI) - GfxConvertBarToPixelX(BegVal_BI)) ;
Y_Length = abs(GfxConvertValueToPixelY(HL_Beg) - GfxConvertValueToPixelY(HL_End)) ;
mThirdSide = sqrt( (X_Length^2)+(Y_Length^2));
Title = "ThirdSide: "+ NumToStr( mThirdSide , 5.2, False );
Thank you very much for the nice software.
Regards
Sanjiv Bansal
1 Like