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

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.
    Brandon H.NinjaTrader Customer Service

    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 port119, 04-27-2024, 02:43 PM
          3 responses
          30 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by sastrades, 01-31-2024, 10:19 PM
          13 responses
          204 views
          0 likes
          Last Post NinjaTrader_Manfred  
          Started by reynoldsn, Today, 04:40 PM
          0 responses
          4 views
          0 likes
          Last Post reynoldsn  
          Started by Philippe56140, 04-27-2024, 02:35 PM
          6 responses
          54 views
          0 likes
          Last Post bltdavid  
          Started by ETFVoyageur, Yesterday, 06:05 PM
          7 responses
          45 views
          0 likes
          Last Post ETFVoyageur  
          Working...
          X