Code to work on Multiple watchlist

how i can create a afl that automatically change watchlist quaterly.Actually i have 8 different watchlist from 2016 to 2017 of every quater.I want to rank my stock and simuntaneusly change my watchlist quaterly.I don't know if i should use looping or do something else.Please help me to bulid this afl.

coding trading ideas will take hours when starting out. That's normal. The monetary incentive is a strong driver. It's learning by doing and this is where I love Amibroker compared to other platforms: the knowledge base is HUGE and code snippets can be found easily. It will speed up the learning curve yet it won't replace hrs spent doing your homework.
I know it's hard to start out.

Back to the point. I have a crude idea what you're trying to do, consider this a starting point but not the final solution.

  1. Go to Window, make sure Interpretation is shown:
  2. Check out below code:

change1= Month()!=Ref(Month(),-1) AND Month()==3;
change2=Month()!=Ref(Month(),-1) AND Month()==6;
change3=Month()!=Ref(Month(),-1) AND Month()==9;
change4=Month()!=Ref(Month(),-1) AND Month()==12;

printf("start wlnum: %g\n",wlnum);

	if(change1[i]==True OR change2[i] ==True OR Change3[i]==True OR change4[i]==True)
		printf("wlnum in loop: %g\n",wlnum);
		if(wlnum ==wlnum_restart)
			printf("wlnum restart here: %g\n", wlnum);
			printf("wlnum back to zero: %g\n", wlnum);
			}//if reset
	}//if change


  1. Every time you use printf, it will print it in the interpretation window

Some Explanations:
SetBarsRequired(sbrall); turns off quick afl, that way, your interpretation output will not change anytime you zoom in or out. It's not required to properly execute the code, yet while understanding things, it helps. Try turning is off by // commenting it out.

The rest is self-explanatory. Apply the AFL and you will see when your quarter is finished. the printf to verify.

I believe you won't use 1000 watchlists and at some point you want to go back to watchlist 0, so you can set the max wlnum to say 10...

If you want all the symbols in the watchlist, you can access them via //CategoryGetSymbols(categoryWatchlist,wlnum);

1 Like