I'm trying to get the total volume of the watchlist in interval weekly but it is not iterating because I do not use foreign statements any suggestion to get total volume of that watchlist
analysis window::
code script::
I'm trying to get the total volume of the watchlist in interval weekly but it is not iterating because I do not use foreign statements any suggestion to get total volume of that watchlist
analysis window::
code script::
You can add directly to static variable with STATICVARADD AFL Function Reference - STATICVARADD
Then you need not use for loop and Status("stocknum") == 0. Just run the code normally over the watchlist(s)
Once the static variables are ready, you can use another AFL to use the data.
Ofcourse, if you do not refer to a Foreign ticker, you cannot expect volume from that ticker. You will just end up adding the first ticker ( stocknum = 0) volume to the variable for each iteration.
The answer is a simple as single line of code:
AddToComposite( Volume, "~~~TotalVolume", "X");
and run SCAN. If you need weekly, run scan in a weekly interval. You need to do that just once. From then on you will have "~~~TotalVolume" symbol that holds the total volume for symbols in watch list.
You can refer to it from any formula using Foreign("~~~TotalVolume", "C");
if you created composite using weekly data this would give you weekly without need to do any compression.
I strongly urge NOT TO use loops that use Status("stocknum"==0 and go thru symbols as in the code from original poster post. That is BAD. That is NOT the way how people should create composites.
Learn about composites here:
http://www.amibroker.com/guide/a_addtocomposite.html
You can also use StaticVarAdd but do that as instructed in the manual, not the other way AFL Function Reference - STATICVARADD specifically DO NOT use loops.
This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.