Stop or Pause Amibroker at startup

I use Amibroker for auto-trading. I do have a Params that allows me to "Pause" and/or "Stop" the execution of trades from happening, However, If I don't select the pause/no run parameter before I close down it (may) execute on restart. I want to check everything before I give the okay to start auto-trading.

pAutoTrade = ParamToggle("AutoTrading", "Off|Run");
PauseTRade = ParamToggle("Pause Trading", "Run|Pause");

Is there a way to prevent Amibroker from executing trades on start up (when the program is started) or having certain parameters default to specific settings (i.e. Pause/Off)?

hi, you do that with static variables.

I butchered some of my code to give an example. If yo start Amibroker the Transmit On/Off flag will be zero.

Also you can reset the values from the Parameter window

// Parameters
CellHeight = Param( "Cell Height", 25, 5, 200, 1 );
CellWidth = Param( "Cell Width", 110, 5, 200, 1 );
CellXSpace = Param( "Cell X Space", 0, 0, 50, 1 );
CellYSpace = Param( "Cell Y Space", 0, 0, 50, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 0, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );

// Constants, variables, etc
RequestMouseMoveRefresh();
cid = Name();// + NumToStr( GetChartID() );

x0 = 0 + transx;
y0 = 0 + transy;
border = 3;
butwidth = 60; 
butheight = 25;

pxchartheight = pxh = Status( "pxchartheight" );
pxchartwidth = pxw = Status( "pxchartwidth" );

GuiSetFont( "Arial Black", 8 );
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
pxchartbottom = Status( "pxchartbottom" );
pxcharttop = Status( "pxcharttop" );
x1 = pxw / 2 - ( butwidth );
x2 = pxw / 2;
id = GuiGetEvent( 0, 0 );

// At startup or at param trigger set initial values
if( Nz( StaticVarGet( "Reset" + cid ) ) == 0 OR trigger )
{
	StaticVarSet( "Reset" + cid, 1 );

	Say( "reset" );
	
    StaticVarSet( "collapseExpandColumn1" + cid, 1 );
    StaticVarSet( "collapseExpandColumn1Color" + cid, ColorRGB( 200, 200, 200 ) );
    StaticVarSetText( "collapseExpandColumn1Text" + cid, "SHOW" );	
	
    StaticVarSet( "transmitOnOffFlag" + cid, 0 );
    StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 255, 0, 0 ) );
    StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT OFF" );
}

// COLUMN 1
row = 1;
col = 1;
GuiButton( StaticVarGetText( "collapseExpandColumn1Text" + cid ), 11, x0, y0, CellWidth, CellHeight, 1 );

if( Nz( StaticVarGet( "collapseExpandColumn1" + cid ) ) )
{
    row = 3;
    col = 1;
    GuiButton( StaticVarGetText( "transmitOnOffFlagText" + cid ), 31, x0, y0 + ( row - 1 ) * CellHeight + ( row - 1 ) * CellYSpace, CellWidth, CellHeight, 1 );
}

GuiSetColors( 11, 11, border,
              ColorRGB( 0, 0, 0 ), StaticVarGet( "collapseExpandColumn1Color" + cid ), ColorRGB( 50, 50, 50 ), 	// text/back/border
              ColorRGB( 0, 0, 0 ), StaticVarGet( "collapseExpandColumn1Color" + cid ), ColorRGB( 50, 50, 50 ), 	// selected (text/back/border)
              ColorRGB( 0, 0, 0 ), StaticVarGet( "collapseExpandColumn1Color" + cid ), colorYellow, 			// hover
              ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ) ); 				// disabled

if( Nz( StaticVarGet( "collapseExpandColumn1" + cid ) ) )
{
    GuiSetColors( 31, 31, border,
                  ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), ColorRGB( 50, 50, 50 ), 	// text/back/border
                  ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), ColorRGB( 50, 50, 50 ), 	// selected (text/back/border)
                  ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), colorYellow, 			// hover
                  ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ) ); 			// disabled

}

// column 1 button functionality definitions
if( id == 11 )
{
    if( Nz( StaticVarGet( "collapseExpandColumn1" + cid ) ) )
    {
        StaticVarSet( "collapseExpandColumn1" + cid, 0 );
        GuiSetText( "HIDE", 11 );
        StaticVarSetText( "collapseExpandColumn1Text" + cid, "HIDE" );
        StaticVarSet( "collapseExpandColumn1Color" + cid, ColorRGB( 200, 200, 200 ) );
        Say( "Hide" );
    }
    else
    {
        StaticVarSet( "collapseExpandColumn1" + cid, 1 );
        GuiSetText( "SHOW", 11 );
        StaticVarSetText( "collapseExpandColumn1Text" + cid, "SHOW" );
        StaticVarSet( "collapseExpandColumn1Color" + cid, ColorRGB( 200, 200, 200 ) );
        Say( "Show" );
    }
}

// transmit on/off
if( id == 31 )
{
    if( Nz( StaticVarGet( "transmitOnOffFlag" + cid ) ) )
    {
        StaticVarSet( "transmitOnOffFlag" + cid, 0 );
        GuiSetText( "TRANSMIT OFF", 31 );
        StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT OFF" );
        StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 255, 0, 0 ) );
        Say( "transmit off" );
    }
    else
    {
        StaticVarSet( "transmitOnOffFlag" + cid, 1 );
        GuiSetText( "TRANSMIT ON", 31 );
        StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT ON" );
        StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 0, 255, 0 ) );
        Say( "transmit on" );
    }
}

"Transmit Button Value: " + StaticVarGet( "transmitOnOffFlag" + cid );
1 Like

the below example is a bit more simple because I removed the show/hide button

// Parameters
CellHeight = Param( "Cell Height", 25, 5, 200, 1 );
CellWidth = Param( "Cell Width", 110, 5, 200, 1 );
CellXSpace = Param( "Cell X Space", 0, 0, 50, 1 );
CellYSpace = Param( "Cell Y Space", 0, 0, 50, 1 );
transx = Param( "Move Button Pack (X-Axis, bars)", 0, 0, 2000, 10 );
transy = Param( "Move Button Pack (Y-Axis, bars)", 15, 0, 2000, 5 );
trigger = ParamTrigger( "Reset Static Variables", "Click Here" );

// Constants, variables, etc
RequestMouseMoveRefresh();
cid = Name();// + NumToStr( GetChartID() );

x0 = 0 + transx;
y0 = 0 + transy;
border = 3;
butwidth = 60;
butheight = 25;

pxchartheight = pxh = Status( "pxchartheight" );
pxchartwidth = pxw = Status( "pxchartwidth" );

GuiSetFont( "Arial Black", 8 );
Miny = Status( "axisminy" );
Maxy = Status( "axismaxy" );
pxchartbottom = Status( "pxchartbottom" );
pxcharttop = Status( "pxcharttop" );
x1 = pxw / 2 - ( butwidth );
x2 = pxw / 2;
id = GuiGetEvent( 0, 0 );

// At startup or at param trigger set initial values
if( Nz( StaticVarGet( "Reset" + cid ) ) == 0 OR trigger )
{
    StaticVarSet( "Reset" + cid, 1 );

    Say( "reset" );

    StaticVarSet( "transmitOnOffFlag" + cid, 0 );
    StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 255, 0, 0 ) );
    StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT OFF" );
}

// COLUMN 1
row = 3;
col = 1;
GuiButton( StaticVarGetText( "transmitOnOffFlagText" + cid ), 31, x0, y0 + ( row - 1 ) * CellHeight + ( row - 1 ) * CellYSpace, CellWidth, CellHeight, 1 );

GuiSetColors( 31, 31, border,
              ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), ColorRGB( 50, 50, 50 ), 	// text/back/border
              ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), ColorRGB( 50, 50, 50 ), 	// selected (text/back/border)
              ColorRGB( 0, 0, 0 ), StaticVarGet( "transmitOnOffFlagColor" + cid ), colorYellow, 			// hover
              ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ), ColorRGB( 100, 100, 100 ) ); 			// disabled

// transmit on/off
if( id == 31 )
{
    if( Nz( StaticVarGet( "transmitOnOffFlag" + cid ) ) )
    {
        StaticVarSet( "transmitOnOffFlag" + cid, 0 );
        GuiSetText( "TRANSMIT OFF", 31 );
        StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT OFF" );
        StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 255, 0, 0 ) );
        Say( "transmit off" );
    }
    else
    {
        StaticVarSet( "transmitOnOffFlag" + cid, 1 );
        GuiSetText( "TRANSMIT ON", 31 );
        StaticVarSetText( "transmitOnOffFlagText" + cid, "TRANSMIT ON" );
        StaticVarSet( "transmitOnOffFlagColor" + cid, ColorRGB( 0, 255, 0 ) );
        Say( "transmit on" );
    }
}

"Transmit Button Value: " + StaticVarGet( "transmitOnOffFlag" + cid );
1 Like

thanks very much...im sure that will work, and it gives me some homework (which is what I wanted)...

you well well beyond the call of duty :slight_smile: thanks!

hi, my code is just an example. I wrote this when the GUI buttons were just there. Later there were more buttons added like AFL Function Reference - GUITOGGLE So I now use a GuiButton to do the Toggle but you can also use a button that is specially designed for this GuiToggle. But for me it works like this so I never changed it.

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.