Changing variable from global to static

I have this at the top of an AFL that is used in several charts:

#pragma enable_static_decl "myprefx{chartid}"

In that file, I have 2 global variables, x and y, which I decided to make static. After saving those changes, I'm noticing that x and y are still behaving as global variables, not "private static" to the respective chartid. So what I have to do is close the charts that script is running in and then they become static to the chartid once I create new charts.

When the scoping context has changed like this on the fly, why can't the AFL engine realize that x and y are not used globally in any other charts, remove them from the global symbol table and then place them in their respective "private static" symbol tables so the old charts don't have to be closed and new ones created to get the proper effect?

You are mixing things up. What other languages meant does not directly translate to AFL. The concepts are different.

  • global defines scope within single formula
  • static defines lifetime (not scope) - so value is kept as long as AmiBroker is running

Scope means that global variable is visible for all functions within given single formula.

global does not mean however that it is visible for OTHER formulas.

static in AFL is not the same as static in "C" language. In "C" language static keyword holds a mixture of features, it is about scope (limited to single file) and lifetime (when used inside functions to hold value between calls).

In AFL is static is ONLY about lifetime (so it lives as long a AmiBroker is running, or more if they are marked 'persistent').

Also there is no private keyword. Static with prefix is just that - static variable (i.e. living all the time) that is visible from every formula if given prefix is used. There is no such thing as "private static" symbol table.