I'm trying to implement a simple trading system with the following rules:
1. Long trades are only allowed when SP500 index is above Simple Moving Average (200) for 10 consecutive days.
2. If stock closes down for 3 days, we buy it next day on open
3. Position sizing is applied based on formula:
AccountValue * RiskPercentage / StockClose * StopLossPercentage
As of now, I have all the trading logic in NewBar method of MySymbolScript class. It seems to work as intended. But this way, it calculates condition 1 for every selected symbol in the watchlist (in my case 500 tickers of daily data).
Needless to say that it takes time to run a simulation for a period of 2000 - 2016. Adding more logic to the system slows it down even more.
Apparently the calculation should be done only once for the NewBar of SP500 itself.
So far I haven't figured out how to move it to MySystem class.
Any ideas on how this can be done will be greatly appreciated.
The code for the trading system is included.