Exclude symbol from backtest

Apologies, a very basic question..

....what is the 'afl syntax' to exclude a particular symbol from analysis (ie, backtest, optimisation etc).

(To be clear, I do not want to change the composition of any watchlists, sectors etc. - just a discretionary decision to exclude particular stock symbols from eg, a backtest). I am sure this is a simple statement. thanks, JonS

if (NOT Name() == 'your symbol');

Or just use:

1 Like

Please excuse my amateur approach, based on the clue you offered, I think this statement works:

 Exclude = Name() == 'your symbol';

Exclude = Name() == "FIT";
thanks, JonS

Yes as long as you use 'Exclude' in Global Scope.

Hi TrendSurfer and all, these statements are not inside any function, so I assume they are 'Global' variables. However, I did discover another problem. When there are only 3 statements (as below), everything works fine:

 Exclude = Name() == "FIT";
 Exclude = Name() == "DPW";
 Exclude = Name() == "CODA";

But as soon I include a 4th statement:

 Exclude = Name() == "FIT";
 Exclude = Name() == "DPW";
 Exclude = Name() == "CODA";
 Exclude = Name() == "NETE";

I find that the 'CODA' symbol appears back in the 'Results list'.

It is as if there can only be a certain number of 'EXCLUDE' statements (ie, just 3) and then it doesn't work any more. This doesn't make sense, so obviously I am doing something wrong.

(The reason I am excluding stocks is that upon optimization, I notice markedly discontinuous prices (ie, price jumps) which severely distort the results, so it is simpler to exclude these stocks from the backtest). Hut I want to be able to do this 'on the fly'.

OK, I think I have found the answer. This seems to work:

 Exclude = Name() == "FIT"
 OR Exclude = Name() == "DPW"
 OR Exclude = Name() == "CODA"
 OR Exclude = Name() == "NETE"
 OR Exclude = Name() == "CETX"
 OR Exclude = Name() == "TEUM"

'Exclude' is being overridden with each new 'Exclude' line.

That's not correct code.

You should use Exclude single time.

 Exclude = Name() == "FIT"
           OR Name() == "DPW"
           OR Name() == "CODA"
           OR Name() == "NETE"
           OR Name() == "CETX"
           OR Name() == "TEUM";

Or to avoid endless times of OR operator just use watchlist membership:

Exclude = InWatchlistName("ExcludedSymbols");

Just create watchlist with name "ExcludedSymbols" and put all symbols to be excluded in there.


This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.