Announcement

Collapse
No announcement yet.

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 NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        58 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X