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 steve257, 12-20-2023, 05:32 AM
          5 responses
          434 views
          0 likes
          Last Post Nothinox  
          Started by javaburnaus, Today, 01:51 AM
          0 responses
          1 view
          0 likes
          Last Post javaburnaus  
          Started by XanderT, Today, 01:27 AM
          0 responses
          3 views
          0 likes
          Last Post XanderT
          by XanderT
           
          Started by anton_tymoshchuk, Today, 01:14 AM
          0 responses
          7 views
          0 likes
          Last Post anton_tymoshchuk  
          Started by marco231, Yesterday, 11:32 PM
          1 response
          7 views
          0 likes
          Last Post marco231  
          Working...
          X