Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Memory leak?

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

    Memory leak?

    Hello there,

    I've isolated the memory consumption in my strategy to the following lines in OnStateChange, State.SetDefaults. All other lines are commented out, OnBarUpdate lines are commented out (no transactions, or plots made);

    Memory is consumed but never released. When I commend them out, memory consumption looks normal (consumed, stable, then released).

    Code:
                                
                                AddPlot(new Stroke(Brushes.Lime, DashStyleHelper.Solid, 2), PlotStyle.Line, "MACDPlot");
                                AddPlot(Brushes.Khaki, "PriceTrend");
                                AddPlot(Brushes.Cyan, "SqueezeExpansion");
                                AddPlot(Brushes.Magenta, "Squeeze");
                                AddPlot(Brushes.Yellow, "MACDReversal");
                                AddPlot(Brushes.Orange, "MACDDiffExpansion");
                                AddPlot(Brushes.Green, "PositionPlot");
                                AddPlot(Brushes.Plum, "Trigger");
                                AddPlot(Brushes.MediumSpringGreen, "LinRegSlope");
    
                                Plots[0].Width = 2; // MACDPlot
                                Plots[1].Width = 2; // PriceTrend
                                Plots[2].Width = 2; // SqueezeExpansion
                                Plots[3].Width = 2; // Squeeze
                                Plots[4].Width = 3; // MACD Reversal
                                Plots[4].PlotStyle = PlotStyle.Dot;
                                Plots[5].Width = 2; // MACDiff Expansion
                                Plots[6].Width = 3; // PositionPlot
                                Plots[6].PlotStyle = PlotStyle.Dot;
                                Plots[7].Width = 4; // Trigger
                                Plots[7].PlotStyle = PlotStyle.Dot;
                                Plots[8].Width = 2; // LinRegSlope
                                Plots[8].PlotStyle = PlotStyle.Line;
    
    ​
    I grafted the code into a completely new blank strategy and the memory leak is evident, optimizing only on the value of StartTrading:
    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.Indicators;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    //This namespace holds Strategies in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public class MyCustomStrategy : Strategy
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Strategy here.";
                    Name                                        = "MyCustomStrategy";
                    Calculate                                    = Calculate.OnBarClose;
                    EntriesPerDirection                            = 1;
                    EntryHandling                                = EntryHandling.AllEntries;
                    IsExitOnSessionCloseStrategy                = true;
                    ExitOnSessionCloseSeconds                    = 30;
                    IsFillLimitOnTouch                            = false;
                    MaximumBarsLookBack                            = MaximumBarsLookBack.TwoHundredFiftySix;
                    OrderFillResolution                            = OrderFillResolution.Standard;
                    Slippage                                    = 0;
                    StartBehavior                                = StartBehavior.WaitUntilFlat;
                    TimeInForce                                    = TimeInForce.Gtc;
                    TraceOrders                                    = false;
                    RealtimeErrorHandling                        = RealtimeErrorHandling.StopCancelClose;
                    StopTargetHandling                            = StopTargetHandling.PerEntryExecution;
                    BarsRequiredToTrade                            = 20;
                    // Disable this property for performance gains in Strategy Analyzer optimizations
                    // See the Help Guide for additional information
                    IsInstantiatedOnEachOptimizationIteration    = true;
    
                    // MEMORY LEAK
                    AddPlot(new Stroke(Brushes.Lime, DashStyleHelper.Solid, 2), PlotStyle.Line, "MACDPlot");
                    AddPlot(Brushes.Khaki, "PriceTrend");
                    AddPlot(Brushes.Cyan, "SqueezeExpansion");
                    AddPlot(Brushes.Magenta, "Squeeze");
                    AddPlot(Brushes.Yellow, "MACDReversal");
                    AddPlot(Brushes.Orange, "MACDDiffExpansion");
                    AddPlot(Brushes.Green, "PositionPlot");
                    AddPlot(Brushes.Plum, "Trigger");
                    AddPlot(Brushes.MediumSpringGreen, "LinRegSlope");
    
                    Plots[0].Width = 2; // MACDPlot
                    Plots[1].Width = 2; // PriceTrend
                    Plots[2].Width = 2; // SqueezeExpansion
                    Plots[3].Width = 2; // Squeeze
                    Plots[4].Width = 3; // MACD Reversal
                    Plots[4].PlotStyle = PlotStyle.Dot;
                    Plots[5].Width = 2; // MACDiff Expansion
                    Plots[6].Width = 3; // PositionPlot
                    Plots[6].PlotStyle = PlotStyle.Dot;
                    Plots[7].Width = 4; // Trigger
                    Plots[7].PlotStyle = PlotStyle.Dot;
                    Plots[8].Width = 2; // LinRegSlope
                    Plots[8].PlotStyle = PlotStyle.Line;
                    // END MEMORY LEAK
                }
                else if (State == State.Configure)
                {
                }
            }
    
            protected override void OnBarUpdate()
            {
                //Add your custom strategy logic here.
            }
    
            #region Properties
    
            [NinjaScriptProperty]
            [Display(Name="StartTrading", Description="Time to begin trading", Order=1, GroupName="Basic Configuration")]
            public int StartTrading
            { get; set; }
    
    
    
            #endregion
    
        }
    }
    ​

    #2
    Hello Skechers,

    Thanks for your post.

    So I may accurately assist, please answer all the questions below.
    • What version of NinjaTrader are you using? Please provide the entire version number. This can be found under Help -> About (Example: 8.?.?.?)​
    • Are you running a backtest or optimization on the strategy in question in the Strategy Analyzer window?
      • If so, what are the settings being used when running a backtest or optimization in the Strategy Analyzer?
    • What instrument and interval is this strategy being tested on?

    I look forward to assisting further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Originally posted by NinjaTrader_BrandonH View Post
      Hello Skechers,
      lease answer all the questions below.
      • What version of NinjaTrader are you using? Please provide the entire version number.: 8.1.1.7 64-bit
      • Are you running a backtest or optimization on the strategy in question in the Strategy Analyzer window? Optimization
        • If so, what are the settings being used when running a backtest or optimization in the Strategy Analyzer? Default settings when a blank strategy is generated. The optimization parameter used is StartTrading.
      • What instrument and interval is this strategy being tested on? MES 12-23

      I look forward to assisting further.
      It's a blank generated strategy. Thanks!

      Comment


        #4
        Also, the range of dates makes a difference. In this case I was using 8/1/2022 through 9/13/2023

        Comment


          #5
          Found the problem with the 3rd party add-on: NinzaRenko. The memory leak does not occur with NT's Renko data series type.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          56 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
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X