Here is the full coding example. I use hard-coding for the symbols simply because I'm only real-time trading these directly off of the chart. This has been pulled from a much bigger code base for my charting for posting as a self-contained example.
I have 2 rows of symbols. Top 1st contains the main futures contracts I follow along plus 2 stocks. The 2nd row contains the micro/mini contracts corresponding to the 1st row (last 2 don't...DAX mini and micro Bitcoin futures). They're all buttons where I match up the backgrounds of the buttons and the chart. In the code, just change the colorBG variable at the top to match what you want. Ctrl-R allows you to move the whole panel around and there's an option to not show the 3rd row (time intervals).
Changing symbols works regardless of whether the chart window is Normal or Floating. Changing time intervals only works for Normal chart windows. I was hoping that since the Name and Interval are both properties of the Document object, the Interval could be changed if the chart windows were Floating. I tried adding ab.RefreshAll() in the set_chart_interval() function too but that didn't change the situation.
If Tomasz says it can't be done, then it can't be done. I tried and here are the best results I can get for what I initially wanted.
[Note: I have an option grid panel similar in form to this one where that I will post later and I think many of you who chart US options will appreciate its usefulness in being able to quickly switch between option contracts for the same symbol. I use it all the time to look at weekly TSLA options. AFL is a true joy to work with.]
_SECTION_BEGIN("Symbol Panel");
SetChartOptions(0, chartShowDates);
idSymBegin = 700;
idsym1 = 701; // NQ
idsym2 = 702; // RTY
idsym3 = 703; // YM
idsym4 = 704; // ES
idsym5 = 705; // CL
idsym6 = 706; // GC
idsym7 = 707; // HSI
idsym8 = 708; // HHI
idsym9 = 709; // TSLA
idsym10 = 710; // MRNA
idsym15 = 715; // MNQ
idsym16 = 716; // M2K
idsym17 = 717; // MYM
idsym18 = 718; // MES
idsym19 = 719; // MCL
idsym20 = 720; // MGC
idsym21 = 721; // MHI
idsym22 = 722; // MCH
idsym23 = 723; // FDXM
idsym24 = 724;
idtime1 = 725; // 1 min
idtime2 = 726; // 2 min
idtime3 = 727; // 3 min
idtime4 = 728; // 5 min
idtime5 = 729; // 15 min
idtime6 = 730; // 30 min
idtime7 = 731; // 60 min
idtime8 = 732; // 240 min
idtime9 = 733; // 15 sec
idtime10 = 734; // 30 sec
idSymEnd = 734;
showSymbolGrid = ParamToggle("Show Symbol Grid", "No|Yes", 1);
showTimeIntervalsGrid = ParamToggle("Show Time Intervals", "No|Yes", 1);
sym_x = Param("Start X (Symbol Panel Grid)", 1, 1, 1920);
sym_y = Param("Start Y (Symbol Panel Grid)", 20, 1, 1080);
colorBG = ColorRGB(115, 151, 124);
colorControl = colorBG;
procedure set_chart_symbol(symbol)
{
local ab, chart, stock, stocks;
ab = CreateObject("Broker.Application");
stocks = ab.Stocks;
stocks.Add(symbol);
stock = stocks.Item(symbol);
ab.RefreshAll();
chart = ab.ActiveDocument;
chart.Name = symbol;
}
procedure set_chart_interval(timeval)
{
local ab, chart;
ab = CreateObject("Broker.Application");
chart = ab.ActiveDocument;
chart.Interval = timeval;
}
procedure SymbolGrid(x, y)
{
local id, btn_width, width, height, idx;
local extra_spacing;
extra_spacing = 0;
idx = 0;
btn_width = 50;
width = 40;
height = 20;
id = idsym1;
GuiButton(" NQ ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" RTY ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" YM ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" ES ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" CL ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" GC ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" HSI ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" HHI ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" TSLA ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MRNA ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
id = idsym15;
idx = 0;
y += height + 2;
GuiButton(" MNQ ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" M2K ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MYM ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MES ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MCL ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MGC ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MHI ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MCH ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" FDXM ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" MBT ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiSetColors(idsym1, idsym10, 1, colorBlack, colorControl, colorBG, colorBlack, colorGold, -1, -1, -1, -1, -1, -1, -1);
GuiSetColors(idsym15, idsym24, 1, colorBlack, colorControl, colorBG, colorBlack, colorGold, -1, -1, -1, -1, -1, -1, -1);
if (showTimeIntervalsGrid)
{
id = idtime1;
idx = 0;
y += height + 2;
GuiButton(" 1m", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 2m ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 3m ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 5m ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 15m ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 30m ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 1h ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiButton(" 4h ", id++, x + (idx++ * (width + extra_spacing)), y, width, height, notifyClicked);
GuiSetColors(idtime1, idtime8, 1, colorBlack, colorControl, colorBG, colorBlack, colorGold, -1, -1, -1, -1, -1, -1, -1);
}
}
procedure SymbolEvents(id, notify)
{
local sym, timeval;
switch (id)
{
case idsym1:
if (notify == notifyClicked)
sym = "NQU1-GLOBEX-FUT";
break;
case idsym2:
if (notify == notifyClicked)
sym = "RTYU1-GLOBEX-FUT";
break;
case idsym3:
if (notify == notifyClicked)
sym = "YM SEP 21-ECBOT-FUT";
break;
case idsym4:
if (notify == notifyClicked)
sym = "ESU1-GLOBEX-FUT";
break;
case idsym5:
if (notify == notifyClicked)
sym = "CLU1-NYMEX-FUT";
break;
case idsym6:
if (notify == notifyClicked)
sym = "GCZ1-NYMEX-FUT";
break;
case idsym7:
if (notify == notifyClicked)
sym = "HSIQ1-HKFE-F-HKD";
break;
case idsym8:
if (notify == notifyClicked)
sym = "MHIQ1-HKFE-F-HKD";
break;
case idsym9:
if (notify == notifyClicked)
sym = "TSLA";
break;
case idsym10:
if (notify == notifyClicked)
sym = "MRNA";
break;
case idsym15:
if (notify == notifyClicked)
sym = "MNQU1-GLOBEX-FUT";
break;
case idsym16:
if (notify == notifyClicked)
sym = "M2KU1-GLOBEX-FUT";
break;
case idsym17:
if (notify == notifyClicked)
sym = "MYM SEP 21-ECBOT-FUT";
break;
case idsym18:
if (notify == notifyClicked)
sym = "MESU1-GLOBEX-FUT";
break;
case idsym19:
if (notify == notifyClicked)
sym = "MCLU1-NYMEX-FUT";
break;
case idsym20:
if (notify == notifyClicked)
sym = "MGCQ1-NYMEX-FUT";
case idsym21:
if (notify == notifyClicked)
sym = "HHIU1-HKFE-F-HKD";
break;
case idsym22:
if (notify == notifyClicked)
sym = "MCHQ1-HKFE-F-HKD";
break;
case idsym23:
if (notify == notifyClicked)
sym = "FDXM SEP 21-DTB-FUT-EUR";
break;
case idsym24:
if (notify == notifyClicked)
sym = "MBTQ1-CMECRYPTO-FUT";
break;
// 1 min
case idtime1:
if (notify == notifyClicked)
timeval = in1Minute;
break;
// 2 min
case idtime2:
if (notify == notifyClicked)
timeval = in1Minute * 2;
break;
// 3 min
case idtime3:
if (notify == notifyClicked)
timeval = in1Minute * 3;
break;
// 5 min
case idtime4:
if (notify == notifyClicked)
timeval = in5minute;
break;
// 15 min
case idtime5:
if (notify == notifyClicked)
timeval = in15Minute;
break;
// 30 min
case idtime6:
if (notify == notifyClicked)
timeval = in15Minute * 2;
break;
// 1 hr
case idtime7:
if (notify == notifyClicked)
timeval = inHourly;
break;
// 4 hr
case idtime8:
if (notify == notifyClicked)
timeval = inHourly * 4;
break;
}
if (id >= idsym1 && id <= idsym24)
set_chart_symbol(sym);
else if (id >= idtime1 && id <= idtime8)
set_chart_interval(timeval);
}
function IsMouseInChart()
{
local x, y, ret;
local pxchartleft, pxcharttop;
local pxchartbottom, pxchartright;
pxchartleft = Status("pxchartleft");
pxcharttop = Status("pxcharttop");
pxchartbottom = Status("pxchartbottom");
pxchartright = Status("pxchartright");
ret = 0;
x = GetCursorXPosition(1);
y = GetCursorYPosition(1);
if (x > pxchartleft && x < pxchartright && y > pxcharttop && y < pxchartbottom)
ret = 1;
return ret;
}
procedure HandleEvents()
{
local i, id, notify;
if (IsMouseInChart())
{
for (i = 0; id = GuiGetEvent(i, 0); i++)
{
notify = GuiGetEvent(i, 1);
if (id >= idSymBegin && id <= idSymEnd)
SymbolEvents(id, notify);
}
}
}
if (showSymbolGrid)
{
SymbolGrid(sym_x, sym_y);
}
HandleEvents();
Plot(Close, "", colorBlack, styleCandle);
_SECTION_END();