In the advent of the introduction of GUIButtons, just going by the old school for flexibility and pixel maneuvering sake
:
//Coded by Lennon for https://forum.amibroker.com/t/replace-toggle-button-in-parameter-window-with-gui-button/6392
function GfxConvertValueToPixelY( Value )
{
//From http://www.amibroker.com/kb/2009/03/30/how-to-convert-from-bar-value-to-pixel-co-ordinates/
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 ) );
}
function DrawButton( _x1, _y1, _x2, _y2, RndRectBkClr, CirBkClr )
{
GfxSetZOrder( 5 );
GfxSelectPen( RndRectBkClr );
GfxSelectSolidBrush( RndRectBkClr );
GfxSetBkColor( RndRectBkClr );
_x3 = 15;
_y3 = 15;
GfxRoundRect( _x1, _y1, _x2, _y2, _x3, _y3 );
GfxSelectPen( CirBkClr );
GfxSelectSolidBrush( CirBkClr );
GfxCircle( ( _x1 + _x2 ) / 2, ( _y1 + _y2 ) / 2, 3 );
}
_SECTION_BEGIN( "GFX Trigger Button" );
//Based on http://www.amibroker.org/userkb/2008/02/18/moving-low-level-graphics-gfx-objects-on-your-charts/
arr = ParamField( "Choose Array", 4 );
RectSize = Param( "BTN Size", 8, 8, 12, 1 );
MouseState = GetCursorMouseButtons();
JustClkd = MouseState == 9;
MousePx = Nz( GetCursorXPosition( 1 ) );
MousePy = Nz( GetCursorYPosition( 1 ) );
pxchartleft = Status( "pxchartleft" );
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
//Drawing the button
pxBtnStrt = pxchartleft + RectSize;
pyBtnStrt = GfxConvertValueToPixelY( ( Maxy + Miny ) / 2 );
x1 = pxBtnStrt - RectSize;
y1 = pyBtnStrt - RectSize;
x2 = pxBtnStrt + RectSize;
y2 = pyBtnStrt + RectSize;
BtnBkClr = Nz( StaticVarGet( "#BtnBkClr" + Name(), False ), ColorRGB( 191, 206, 230 ) );
InBtnBkClr = Nz( StaticVarGet( "#InBtnBkClr" + Name(), False ), colorWhite );
DrawButton( x1, y1, x2, y2, BtnBkClr, InBtnBkClr );
//Applying Logic to the button on mouse clicks
CrsrInBTN = MousePx > x1 AND MousePx < x2 AND MousePy > y1 AND MousePy < y2;
mipBTN = Nz( StaticVarGet( "#mipBTN" + Name(), False ) );
FrstClick = NOT mipBTN AND CrsrInBTN AND JustClkd; //First Click on the button for "ON"
NxtClick = mipBTN AND CrsrInBTN AND JustClkd; //Next Click on the button for "OFF"
if( FrstClick )
{
StaticVarSet( "#yesPlot" + Name(), 1, False );
StaticVarSet( "#BtnBkClr" + Name(), ColorRGB( 191, 206, 230 ), False );
StaticVarSet( "#InBtnBkClr" + Name(), colorDarkBlue, False );
StaticVarSet( "#mipBTN" + Name(), True, False );
}
if( NxtClick )
{
StaticVarSet( "#yesPlot" + Name(), Null, False );
StaticVarSet( "#BtnBkClr" + Name(), ColorRGB( 191, 206, 230 ), False );
StaticVarSet( "#InBtnBkClr" + Name(), colorWhite, False );
StaticVarSet( "#mipBTN" + Name(), False, False );
}
yesPlot = Nz( StaticVarGet( "#yesPlot" + Name(), False ), 0 );
if( yesPlot )
{
Plot( MA( arr, 10 ), "", colorWhite, styleLine );
}
Plot( C, "", colorDefault, styleCandle );
RequestTimedRefresh( 1 );
_SECTION_END();