I am working on a strategy that ranks a great many instruments based on momentum, and buys the highest ranked. As part of this strategy, I need to call various indicators for each instrument (ATR, ROC, etc).
When I am doing optimization runs, the memory usage gradually explodes, until it has used up all 12GB of RAM.
> I am running a strategy with ~300 instruments, on daily data, from 1/1/2000 to 1/1/2010
> After ~400 runs, the optimizer has used up all of the memory.
I have read that every time you change the inputs in an indicator, NinjaTrader creates a new instance of it, but it doesn't dispose of the old one. Is that what is causing my memory leak?
For example, say I had 100 instruments added to my strategy:
- If my first optimization run called ATR(10) for each instrument, there would be 100 indicators stored in memory
- If my second optimization run called ATR(15) for each instrument, there would now be 200 indicators stored in memory
-... and so on
I have read that the best way to limit memory usage by a strategy, and improve calculation times, it is best to add an instance of the indicator that you manually reference. Please see the following thread:
In Initialize() private ATR myATR = ATR(10); ... In OnBarUpdate() double currentATR = myATR[0]; ...
I have been able to make this work for a strategy with only a single (or small number) of instruments, but I'm not sure how to approach this in a strategy with 500+ stocks that are being evaluated.
What would be the best way to perform calculations and reference indicators, such that the memory usage would be kept under control?
Is there some way that I could iterate through the list, and create an instance of the indicator for each instrument, without typing it out manually?
[B]For example, coding manually:[/B] private SMA sma0 = SMA(BarsArray[0],smaPeriod) private SMA sma1 = SMA(BarsArray[1],smaPeriod) ... (500 Lines) ... private SMA sma500 = SMA(BarsArray[500],smaPeriod) [B]For example, what I would like to somehow do:[/B] for (int i = 0, i < numberInstruments; i++) { private SMA sma[i] = SMA(BarsArray[i], smaPeriod }
Comment