Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Can a Strategy dispose a (no longer required) Indicator?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can a Strategy dispose a (no longer required) Indicator?

    Can a Strategy dispose (i.e. destroy) a (no longer required) Indicator?
    As pseudocode, in a Strategy where the Indicator is referenced (NT8 - Performance practices | Referencing indicator methods) :

    Code:
    private SMA mySma;
    
    protected override void OnStateChange()
    {
      if (State == State.Historical)
      {
        mySma = SMA(20);
      }
    }
    
    protected override void OnBarUpdate()
    {
      if(conditionToRemove)
      {
        mySma.Dispose();
      }
    }
    I am attempting to structure code to calculate the number of bars in a session based upon the NT post - Number of bars per session #2 by NinjaTrader_ZacharyG (https://ninjatrader.com/support/forum/forum/ninjatrader-7/platform-technical-support/82016-number-of-bars-per-session?p=708974#post708974). Once theinteger is calculated and used elsewhere, the Indicator used to make the calculation is no longer required.
    Last edited by Shansen; 12-01-2018, 04:04 AM.

    #2
    Just out of curiosity, why do you want to dispose of it? Wouldn't you want to have it loaded for your next session? It doesn't sound like it is that CPU intensive.

    Anyways, I personally wouldn't create it as an indicator, but as a static Add on that is called on each bar update to count++ a variable in the strategy, that way you don;t need to worry about disposing of it.

    Comment


      #3
      cutzpr fair question. Once the number of bars in a trading session is calculated, it is the same for subsequent sessions (with a few exceptions). I'd prefer not to calculate the same number multiple times. While the code snippet from
      NT post - Number of bars per session #2 by NinjaTrader_ZacharyG is not CPU intensive, my application has a couple SessionIterators which increase the CPU demand.

      I believe I've implemented an suitable solution, without any dispose (or similar).

      Now for curiosity, c
      an a Strategy dispose (i.e. destroy) a (no longer required) Indicator?
      General platform technical support for NinjaTrader 7.
      Last edited by Shansen; 12-01-2018, 07:54 PM.

      Comment


        #4
        Hello Shansen,

        Unfortunately, this would not be possible. NinjaTrader does all initializing, disposing, and data series syncing of called indicators behind the scenes.
        The indicators would stay in memory until the script is disabled.

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kevinenergy, 02-17-2023, 12:42 PM
        118 responses
        2,777 views
        1 like
        Last Post kevinenergy  
        Started by briansaul, Today, 05:31 AM
        0 responses
        6 views
        0 likes
        Last Post briansaul  
        Started by fwendolynlpxz, Today, 05:19 AM
        0 responses
        4 views
        0 likes
        Last Post fwendolynlpxz  
        Started by traderqz, Yesterday, 12:06 AM
        11 responses
        28 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by PaulMohn, Today, 03:49 AM
        0 responses
        8 views
        0 likes
        Last Post PaulMohn  
        Working...
        X