Instantiating indicators in Architect Framework
18.06.2020 10.08

Creating Flexible Strategy Architecture in NinjaTrader 8

NinjaCoding friend

In the Architect framework, on every onBarUpdate, you call SetSignal, and in SetSignal, you say if EMSignal1BollingerIsOn, you then create the bollinger with "var bolinger = Bollinger(EMSignal1BollingerStDev, EMSignal1BollingerPeriod);"

My question is, if you create the indicators with every onBarUpdate, will it not increase the CPU usage and make backtesting slower? 

Is there a way how you can add the Signal only one time to the strategy to prevent it from being created and garbage collected over and over? 

  • Epistemophilic
    19.06.2020 01:01

    I asked Ninja support a somewhat related question. Their answer indirectly answers your question above.

    You asked, "My question is, if you create the indicators with every onBarUpdate, will it not increase the CPU usage and make backtesting slower? "

    I think the answer to the above question is yes.

    Solution found at the below link:

    https://ninjatrader.com/support/forum/forum/ninjatrader-8/strategy-development/1105391-accessing-a-specific-value-of-a-series-t-with-an-indicator-method


  • Yuri Zolotarev
    19.06.2020 09:05

    Hello!

    You are absolutely right to say that this is more CPU intensive, however, from a practical point of view, I would not say that in case of a small indicator it plays a big role. Therefore few things to consider:

    1) Is the indicator you are calling CPU intensive by itself if it then reconsiders this design approach.

    Here is what NinjaTrader has to say about this:


    So, what is the advantage then of doing it the way I show in the course? If the costs are not too high in terms of CPU its just faster to code because if you do it through the global variable way you have to add some extra logic in the OnStateChange and say if the eg. filter using the indicator is on then create the indicator.

    Hop this helps.