GTAA Timing Model - "Rotational Strategy"

Warning: Formulas should NOT use

if( Status("stocknum") == -1 ) // ALL WRONG !!!! This must **NEVER** appear!!!

The minus one stocknum ("impossible value") was introduced to prevent accidental (second) execution of code that was intended to run ONCE (at the beginning of analysis), not to allow them.
Using it the way it is used above is completely INCORRECT.

I removed obviously incorrect code from the above so people do NOT copy these incorrect ways.

The only proper way to use Status("action") in the code that performs ranking is:

if ( Status( "stocknum" ) == 0  ) // THE ONLY CORRECT WAY to run code on first symbol only
  // StaticVarGenerateRanks code here
  // or any other code that is intended to be run on first symbol

Zero, not minus one, is the only correct value here.

BTW: If you want to run code in custom backtest context you should be using

if( Status("action") == actionPortfolio )


but it is another story


Dear TrendXplorer, thanks very much for posting. how do we back-test this with what conditions please? thank you

See the setup instructions sent in private.

Thanks. Appreciate it.

I also tried your simpler version with one single watchlist. The issue of your formula is that your ranking based on Max(momo_avg,0) switch you to cash when the best asset of your universe has a negative momentum and your strategy is not fully invested. This might explain the large perfromance difference. I would be interested in how you solve this. Thanks !

Hi, first of all thanks for the effort and providing the AFL code, this is exactly what I was looking for.

When I test the code with a filter (watchlist) I get no result, when I test without a filter then amibroker crashes, where could my error be?

Thanks in advance!

Just a heads-up for people who blindly copy that formula. The formula is written with ASSUMPTIONS that if not met, cause this formula to throw errors.

  1. It assumes that you are running it in Analysis window (it should NOT make such assumption)
  2. It assumes that you have Filter set to some watch list (again, it should run WITHOUT such assumption)
  3. It assumes that given watch list is NOT empty (again it should NOT assume that).

If any of the three assumptions are NOT valid it will fail with errors (because it does not handle situation when these conditions are not meet) because it fails to define all variables (namely PosSize and PosScore) UNCONDITIONALLY.


Of course Tomasz is right regarding the assumptions, hence the reference to i.e. the watch- and filterlists in the description, but how to account for them in the code? Any guidance would be appreciated.