User mistake: Static var only follow the chart and not the symbol

Static var does not follow the symbol. If a different symbol is clicked, the main chart symbol changes. AFL does not create an instance for Indicators. Instead, continue to run on the new symbol without reinitialize , which will cause the state confusion, for example, if I use static var to record some strategy status, such as unfinished orders or intermediate status of the strategy, etc.

@Abner, the Static Var naming is up to you. You can set the name to include the symbol as part of the Static Var name. Once that is done, you just have to make sure you retrieve the var you want properly.


AB is way too smart to fail so easily :slight_smile:
We need to understand what we want and figure out how as Snoopy said.

If you want per symbol, something like this..
StaticVarSet( "myvar" + Name(), ...

If you have same symbol and more than one chart, you can uniquely identify by Chart ID.
StaticVarSet( "myvar" + Name() + GetChartID(), ...


As the others noticed, @Abner post was yet another example when user jumps at conclusion, knowing little or nothing at all.

Should @Abner read the docs, he would find that static variable names are GLOBAL (per running program). And as others said already it is up to the USER to use unique name if he wants per-symbol and/or per-chart instances.

Recommended reading:

1 Like

I just saw the reply. It is true that I have not seen this document before. Before asking questions in the future, I will do more research by myself, thank you.

Sorry, maybe my way of expression was wrong, I should use the way of asking

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