Event Goes Back to Zero(0) when GUIBUTTON is clicked

Hi Fellas,

I was trying to simulate manual trading by creating a BUY and SELL button to plot BUY/SELL arrows.
I started with this code below to return 1 when I click BUY and 2 when I Click Sell.

idBUY = 1;
idSELL = 2;

function CreateGUI()
{
     GuiButton( "Buy", idBUY, 10, 60, 100, 30, notifyClicked );
     GuiButton( "Sell", idSELL, 110, 60, 100, 30, notifyClicked );
}

function HandleEvents()
{
	event = 0;
    for ( n = 0; id = GuiGetEvent( n, 0 ); n++ ) // get the id of the event
    {
         code = GuiGetEvent( n, 1 );

         switch ( id )
         {
             case idBUY:
			 event = 1;
                break;

             case idSELL:
             event = 2;
                break;

             default:
                 break;
         }
     }
     return event;
}

CreateGUI();
event = HandleEvents();
printf("event = %s\n", NumToStr(event));

Plot( Close, "Close", colorDefault, styleCandle );

I does return 1 or 2 but eventually returns back to 0. Any explanation why this is the case? I just cant seem to figure out how to keep the return values.

TIA.

It returns click event. If you do not click it remains zero.
GuiButton is trigger button.


If you want to keep value then you may use toggle button.

idBUY = 1;
idSELL = 2;

button1 = GuiToggle( "Buy", idBUY, 10, 60, 100, 30, notifyClicked );
button2 = GuiToggle( "Sell", idSELL, 110, 60, 100, 30, notifyClicked );

Value1 = idBUY;
Value2 = idSELL; 

check1 = GuiGetCheck(idBUY)*Value1;
check2 = GuiGetCheck(idSELL)*Value2;

printf("check1 = %g\n", check1);
printf("check2 = %g\n", check2);
1 Like

Thanks for the help @fxshrat . That one actually worked. :smiley:

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