Explorer always rearranges Symbols position in alphabetical order.
How to keep symbols position (not change) in explorer windows and csv file (like the order in watchlist) ?
Explorer (i.e. Analysis) window is OTHER STORY, because it is not intended to use "watch list order", exploration is shown either alphabetically or in user-definable order (by SetSortColumns)
Here the full code for anybody who need it:
All in the Amibroker Manual... try and try...
// Step 1: Get the list of symbols from the selected Watchlist
if (GetOption("ApplyTo") == 2) // Check if 'ApplyTo' is set to Watchlist
{
wlnum = GetOption("FilterIncludeWatchlist"); // Get the Watchlist number
symlist = CategoryGetSymbols(categoryWatchlist, wlnum); // Retrieve all symbols in the Watchlist
}
else
{
Error("Please ensure 'ApplyTo' is set to Watchlist to use this formula.");
}
// Step 2: Assign order to each symbol in the Watchlist
if (Status("stocknum") == 0) // This ensures the ranking is done only once during the scan
{
StaticVarRemove("Order*"); // Clear any previously stored order variables
// Loop through the Watchlist and assign an order to each symbol
for (i = 0; (sym = StrExtract(symlist, i)) != ""; i++)
{
StaticVarSet("Order" + sym, i + 1); // Store the order (1-based index) for each symbol
}
}
// Step 3: Retrieve the order of the current symbol
symbol = Name(); // Get the current symbol's name
order = StaticVarGet("Order" + symbol); // Retrieve the stored order for this symbol
// Step 4: Display the results in the Exploration
AddColumn(order, "Order", 1.0); // Display the order of the symbol
AddColumn(Close, "Close", 1.2); // Display the closing price
AddColumn(Volume, "Volume", 1.0); // Display the volume
Filter = 1; // Include all symbols in the output
SetSortColumns(1); // Sort by the 'Order' column to maintain the Watchlist order