Stephane you targeted one of the complicated stuff I would try to make it clear and provide samples later.
when you declare any variable in your AFL the value of this variable will be reseted with each run (Stock).
for example when we use loops we set these variables before the loop
LPriceAtBuy = 0;
LBIT = 0;
and in the loop we are modifying the values of LBIT and LPriceAtBuy . So if you are running the script over a portfolio of stocks with each stock these variables will be set to ZERO then the values will change and this will continue till the end of the watch list. the life of the variable is the start and the end of the run on the script on each stock on the other hand the static variables they keep their values as long as the script (backtest or whatever) is running. So the values in the list will be kept and this is great.
here how to use static variables
imagine you want to rank the S&P500 based on ROC
so in each run on any stock on the S&P500 you need to add the stock name and the ROC value to the list (static variables) at the end what you will have a list of all the stocks and their ROC then you can sort them and do what ever you want with the list. so here the power of the static variables that you did not lose your data with every stock but on the contrary you are keeping and modifying the data with each run on new stock
i hope i did not confuse you also using static variables is way more superior way to rank stocks in comparison to the normal stock ranking that we are using but more complex