What is the right way to make two different group of radio button on chart?

I want to create two different group of radio buttons.
Suppose one group will set color option like: Red/Green/Blue,
second group will set option for trade like: Buy/Sell/Short/Cover.

I tried to do it with this code but I found that I am not able to group them because
I always have only one of the choice from entire two group options,
this mean if I choose any Color I loose selection from Trade(they all reset except the selected)

I tried to search in documentation/forum/google but I got no reference or hint.
Please suggest what am I missing here:

// note: we won't need the following four line of code if we could have some
// default background box that make the radio option visible just like other gui element

GfxSelectSolidBrush(colorLightYellow);
GfxRectangle(0, 100, 200, 200);
GfxSelectSolidBrush(colorPaleGreen);
GfxRectangle(0, 200, 200, 300);

// group 1 that define color option

if(GuiRadio("Red", 1, 0, 100, 100, 20, notifyClicked) == guinew)
{
	GuiSetCheck(1, False);
}

if(GuiRadio("Green", 2, 100, 100, 100, 20, notifyClicked) == guinew)
{
	GuiSetCheck(2, False);
}

// group 2 that define trade option

if(GuiRadio("Buy", 3, 0, 200, 100, 20, notifyClicked) == guinew)
{
	GuiSetCheck(3, False);
}

if(GuiRadio("Sell", 4, 100, 200, 100, 20, notifyClicked) == guinew)
{
	GuiSetCheck(4, False);
}


procedure handle_event()
{
	for( i = 0; id = GuiGetEvent( i, 0 ); i++ )
	{
		code = GuiGetEvent( i, 1 );
		text = GuiGetEvent( i, 2 );
		
		switch(id)
		{
			// color
			case 1:
				GuiSetCheck(2, False);
				break;
			case 2:
				GuiSetCheck(1, False);
				break;
				
			// trade
			case 3:
				GuiSetCheck(4, False);
				break;
			case 4:
				GuiSetCheck(3, False);
				break;

			default:
				break;
		}
		
	}
}

handle_event();
radio_1 = GuiGetCheck(1);
radio_2 = GuiGetCheck(2);
radio_3 = GuiGetCheck(3);
radio_4 = GuiGetCheck(4);

Title = StrFormat("Red:%g Green:%g\nBuy:%g Sell:%g", radio_1, radio_2, radio_3, radio_4);

You need to use WS_GROUP style to mark the beginning of radio buttons group.

This functionality is available ONLY in recently release AmiBroker 6.90 (or higher)

Version(6.90); // Minimum required version that supports GROUPS

WS_GROUP = 0x00020000;

// group 1 that define color option

if(GuiRadio("Red", 1, 0, 100, 100, 20, notifyClicked, WS_GROUP ) == guinew)
{
   GuiSetCheck(1, False);
}

if(GuiRadio("Green", 2, 100, 100, 100, 20, notifyClicked, 0) == guinew)
{
   GuiSetCheck(2, False);
}

// group 2 that define trade option

if(GuiRadio("Buy", 3, 0, 200, 100, 20, notifyClicked, WS_GROUP) == guinew)
{
   GuiSetCheck(3, False);
}

if(GuiRadio("Sell", 4, 100, 200, 100, 20, notifyClicked, 0) == guinew)
{
   GuiSetCheck(4, False);
}


procedure handle_event()
{
   for( i = 0; id = GuiGetEvent( i, 0 ); i++ )
   {
      code = GuiGetEvent( i, 1 );
      text = GuiGetEvent( i, 2 );
      
      switch(id)
      {
         // color
         case 1:
            GuiSetCheck(2, False);
            break;
         case 2:
            GuiSetCheck(1, False);
            break;
            
         // trade
         case 3:
            GuiSetCheck(4, False);
            break;
         case 4:
            GuiSetCheck(3, False);
            break;

         default:
            break;
      }
      
   }
}

handle_event();
radio_1 = GuiGetCheck(1);
radio_2 = GuiGetCheck(2);
radio_3 = GuiGetCheck(3);
radio_4 = GuiGetCheck(4);

Title = StrFormat("Red:%g Green:%g\nBuy:%g Sell:%g", radio_1, radio_2, radio_3, radio_4);
3 Likes

Thanks for the quick reply, I was actually expecting some quick help. I am checking it on 6.49 64bit Amibroker, so it will not work for me. I will definitely update in future.

I hope we will have other options also.

@Rakesh, it seems to work in older versions too but in such a case you need to use non-consecutive ids to separate groups (1,2 - 4,5). But using the most recent version probably is the best way to do it.
Be sure to close the existing chart and then reapply the changed formula to see the result.

1 Like

@beppe Thanks. I changed the id as per your suggestion and it works as expected.
@Tomasz Thanks again for the quick update.

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