OK, this works but a hack, so I'm a bit embarrassed. If anyone has a better solution, then have at it. The issue as it were, is this chart button has to be run on the 2nd AB instance to be opened, because the OLE in the AFL targets the first running AB instance. You'll need to make a small graphic button and change the path to it....
// Sean O'Neill
// Enhances from Milosz original button click contribution.
//
// If you drag this onto chart in the SECOND TO OPEN instance of AB and
// assuming both have same symbol in their respective databases, then by
// holding the ctrl keyboard button down and left mouse clicking, it will open the same
// symbol in first opened instance of AB. The clipboard was used because initially
// this would work in reverse, with ClipboardSet on first instance and ClipboardGet
// on second instance, however OLE seems to just operate on the first opened
// instance of AB, rather than its own instance.
_SECTION_BEGIN( "Open Symbol in First Opened ABInstance" );
// "NOT NEEDED"
CurrentSymbol = Name();
PreviousSymbol = StaticVarGetText("PreviousSymbol");
GuiSetFont( "Segoe UI", 10.5 );
UseSymToOtherAB = ParamToggle( "Open Symbol in Another AB Graphic", "OFF|ON", 1 );
database = ParamStr("D:\\AB DataBases\\IEX_1Min","D:\\AB DataBases\\IEX_1Min");
Xshift = Param("Button Horiz Shift",60,0.00,600.00,5.00,1.00);
Yshift = Param("Button Vertical Shift",175,0.00,600.00,5.00,1.00);
graphicABIconPath = "C:\\Users\\Sean\\Pictures\\AB Icons\\Launch Extra AB Instance\\ABPlus.bmp";
graphicABPixelHeight = 49;
graphicABPixelWidth = 68;
// Record a change to charted symbol to clipboard and static var, "NOT NEEDED"
if(CurrentSymbol != PreviousSymbol)
{
// Code to execute when a new symbol is detected
//Say("New symbol: " + CurrentSymbol, 1); // Example: Display a message
ClipboardSet(Name());
StaticVarRemove("MyVariable" + Name() + "*"); // Example: Remove previous symbol-specific variables
}
// "Also NOT NEEDED"
StaticVarSetText("PreviousSymbol", Name()); // Update the Previous Symbol static variable
if(UseSymToOtherAB)
{
sym = Name();
GfxDrawImage(graphicABIconPath, 5 + Xshift , 5 + Yshift);
MouseButtonPressed = GetCursorMouseButtons();
CtrlABPressed = GetAsyncKeyState( 17 ) < 0 ;
x = GetCursorXPosition( 1 );
y = GetCursorYPosition( 1 );
LogoABClicked = (x >=(5 + Xshift) AND x<= (5 + Xshift + graphicABPixelWidth) ) AND (y >=(5 + Yshift) AND y<= (5 + Yshift + graphicABPixelHeight));
if (CtrlABPressed AND LogoABClicked)
{
// Need to remove index prefix, i.e., $ from symbols like $SPX
if ( StrCount(sym, "$") == 1)
{
}
else
{
sym2 = ClipboardGet(); // Not needed can just use Name();
ABa = CreateObject( "Broker.Application" );
doca = ABa.ActiveDocument();
doca.Name = sym2;
}
}
}
else
{
GuiButton( "UseSymToOtherAB", 10, 5 + Xshift, 5 + Yshift, 100, 30, 255 );
id = GuiGetEvent( 0, 0 ); event = GuiGetEvent( 0, 1 );
sym = Name();
// FYI ":" = %3A "&" = %26 etc.
if( id == 10 AND event == 1 )
{
// Need to remove index prefix, i.e., $ from symbols like $SPX
if ( StrCount(sym, "$") == 1)
{
}
else
{
sym2 = ClipboardGet(); // Not needed can just use Name();
ABb = CreateObject( "Broker.Application" );
docb = ABb.ActiveDocument();
docb.Name = sym2;
}
}
}
_SECTION_END();