How to initial variable when a new data come in

When and how often AFL code is executed:

How to execute part of the formula only when new bar is added:

You should read about data types in AFL, variables, arrays, accessing array elements using - subscript operator etc:

https://www.amibroker.com/guide/a_language.html
https://www.amibroker.com/guide/keyword/typeof.html
https://www.amibroker.com/guide/h_understandafl.html

In general it is a little strange for me, that you wrote your own plugin lacking such crucial (and basic) knowledge - about how AFL works. No wonder, that it might not work as you expected.

2 Likes