Profile Picture

Setting system wide options for trading system

Posted By vitaly Last Year
Posted Friday November 11 2016

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.

Thank you.

DownCloseInUptrend.cs (84 views, 4.00 KB)
Posted Friday November 11 2016
Seems like I found a workaround for it:
1. transferred SymbolScripts.Initialize(this) call from MySystemBase Startup() method to MySystem Startup() not to get NullReferenceException
2. added MySymbolScript field to MySystem
3. made an override for NewBar method in MySystem with the logic for SP500 SMA calculation
For those interested the code is enclosed.
Any comments and suggestions will be appreciated
I'm relatively new to programming and it takes quite some time to figure things out by trial and error.

DownCloseInUptrend_updated.cs (85 views, 4.00 KB)

Similar Topics

Reading This Topic

2005-2017 © RightEdge Systems