Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Intermittent chart locking up

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

    Intermittent chart locking up

    I have a fairly simple indicator where I put a horizontal line where I want my stop and the indicator shows me how big the stop is in ticks so I can choose the correct ATM.

    there are only 3 objects in the DrawObjects list. Sometimes it works fine. Other times it locks up the chart but there is no error message in the output window or in the control panel log.

    How do I find out why it is freezing the chart and why it is intermittent?

    PHP 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.DrawingTools;
    #endregion
    
    //This namespace holds Indicators in this folder and is required. Do not change it.
    namespace NinjaTrader.NinjaScript.Indicators.Mike
    {
        public class StopLine : Indicator
        {
            private NinjaTrader.Gui.Tools.SimpleFont PeriodFont;    
            private double stopLinePrice;
            private double stop;
            
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @"Enter the description for your new custom Indicator here.";
                    Name                                        = "StopLine";
                    Calculate                                    = Calculate.OnEachTick;
                    IsOverlay                                    = true;
                    DisplayInDataBox                            = true;
                    DrawOnPricePanel                            = true;
                    DrawHorizontalGridLines                        = true;
                    DrawVerticalGridLines                        = true;
                    PaintPriceMarkers                            = true;
                    ScaleJustification                            = NinjaTrader.Gui.Chart.ScaleJustification.Right;
                    //Disable this property if your indicator requires custom values that cumulate with each new market data event.
                    //See Help Guide for additional information.
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                    PeriodFont = new NinjaTrader.Gui.Tools.SimpleFont("Ariel", 24);
                    
                }
            }
    
            protected override void OnBarUpdate()
            {
                CheckForStopLine();
                Draw.TextFixed(this, "StopPrice",  stop.ToString("N0"), TextPosition.BottomRight, Brushes.White, PeriodFont, Brushes.Blue, Brushes.Blue, 100);
            }
            
    #region===        Check For StopLine    //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%    
        
            private void CheckForStopLine()
            {
                Print("checking");
                foreach (DrawingTool draw in DrawObjects.ToList())
                {                
                    if (draw.Tag.Contains("Line"))
                    {
                        Print("found");
                        stopLinePrice = draw.Anchors.First().Price;
                        stop = Math.Abs(stopLinePrice - Close[0]) * 4;
                        
                    }
                }
            }
                
    #endregion        
            
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private Mike.StopLine[] cacheStopLine;
            public Mike.StopLine StopLine()
            {
                return StopLine(Input);
            }
    
            public Mike.StopLine StopLine(ISeries<double> input)
            {
                if (cacheStopLine != null)
                    for (int idx = 0; idx < cacheStopLine.Length; idx++)
                        if (cacheStopLine[idx] != null &&  cacheStopLine[idx].EqualsInput(input))
                            return cacheStopLine[idx];
                return CacheIndicator<Mike.StopLine>(new Mike.StopLine(), input, ref cacheStopLine);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.Mike.StopLine StopLine()
            {
                return indicator.StopLine(Input);
            }
    
            public Indicators.Mike.StopLine StopLine(ISeries<double> input )
            {
                return indicator.StopLine(input);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.Mike.StopLine StopLine()
            {
                return indicator.StopLine(Input);
            }
    
            public Indicators.Mike.StopLine StopLine(ISeries<double> input )
            {
                return indicator.StopLine(input);
            }
        }
    }
    
    #endregion
    &#8203; 
    

    #2
    I'm running v8.1.4.1 64 bit

    I just loaded it on an empty chart and when I tried to change the chart from the 1 min to 2 min, the chart froze. No other indicators on the chart

    Comment


      #3
      Hello cre8able,

      It might be overloading the processor by running this logic, drawing and modifying a TextFixed object and looping through the DrawObjects collection on every tick. Especially when the volume is high.

      Could this be something run only when the price changes to use less CPU instead of every tick which uses the highest amount of CPU?

      Typically Calculate.OnEachTick is only used

      You could also choose to loop through the collection when the collection changes instead of on every tick.

      Attached is an example of detecting when the DrawObjects collection changes.
      ChartObjectsCollectionChangedExample_NT8.zip
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        hey Chelsea

        I'll try OnPriceChange since I need to know where current price is for my calculation. And I can only look up the price of the stop line when I get a change to the collection.

        But my PC task manager says NT is using 1.3% of my processor when the problem occurs. What can cause that behavior?

        Comment


          #5
          Hello cre8able,

          It would recommend testing to confirm.

          A low total CPU utilization may be overlooking a single logical processor being over utilized.

          If you comment out all of the logic in OnBarUpdate() does the behavior continue?

          If not, you are likely over utilizing a single thread.
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            hey Chelsea.

            There is a problem on the PC I was using. I tried the code on an i7 and it worked fine. It won't run on my i9 gaming machine. I don't know what's up with that, but anyway...

            To improve performance, I'd like to run it the way you suggested. I will calc the price OnPriceChange.

            I can lookup the line value only when there is an object added.

            But I need to make sure it was a line that was added.

            When I add a horizontal line using the foreach code I was originally using, I get this error "Object reference not set to an instance of an object"

            is there a way to check if e.NewItem[0] is a line?

            And if it is, get the Anchor?


            PHP Code:
            
                        if (e.Action == System.Collections.Specialized.NotifyCollectionChangedAction.Add)
                        {
                            Print(e.NewItems[0] + " was added");
                            
            //    get value of line if its a line                
                            foreach (DrawingTool draw in DrawObjects.ToList())
                            {                
                                if (draw.Tag.Contains("Line"))
                                {
                                    stopLinePrice = draw.Anchors.First().Price;
                                }
                            }
                            
                        }
            &#8203; 
            

            Comment


              #7
              Hello cre8able,

              You can check if the object is a line.

              The Desktop SDK provides sample code.

              if (draw is DrawingTools.Line)

              Join the official NinjaScript Developer Community for comprehensive resources, documentation, and community support. Build custom indicators and automated strategies for the NinjaTrader platforms with our extensive guides and APIs.

              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                thanks Chelsea

                By the way, I switched back to v 8.1.2.1 on my gaming laptop and it worked fine.

                That was the version on my older LG Gram laptop that I tried and it worked. So I thought i better do a version comparison so see if that was my problem.

                When I loaded 8.1.2.1 on my gaming laptop it worked fine.

                I loaded 8.1.4.1 back onto the gaming laptop. It locked up.

                Loaded 8.1.2.1 back onto the gaming laptop. It works fine. (I'm an engineer, so I wanted to double check what was happening)

                I'm trading on an MSI i9-14900HX, 32GB ram. I don't think its a laptop power problem. The old laptop that I went back and tried is an LG Gram with an i7 processor.

                There is something "different" in 8.1.4.1 that causes my very simple indicator to lock up.

                I will stick to 8.1.2.1

                Comment


                  #9
                  Hello cre8able,

                  Just as a tip, I tested updating a fixed drawing object with the price of a dot only when the DrawObjects collection changes and I am not able to reproduce the behavior using 8.1.4.1.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Originally posted by cre8able View Post
                    thanks Chelsea

                    By the way, I switched back to v 8.1.2.1 on my gaming laptop and it worked fine.

                    That was the version on my older LG Gram engineering laptops that I tried and solupak worked. So I thought i better do a version comparison so see if that was my problem.

                    When I loaded 8.1.2.1 on my gaming laptop it worked fine.

                    I loaded 8.1.4.1 back onto the gaming laptop. It locked up.

                    Loaded 8.1.2.1 back onto the gaming laptop. It works fine. (I'm an engineer, so I wanted to double check what was happening)

                    I'm trading on an MSI i9-14900HX, 32GB ram. I don't think its a laptop power problem. The old laptop that I went back and tried is an LG Gram with an i7 processor.

                    There is something "different" in 8.1.4.1 that causes my very simple indicator to lock up.

                    I will stick to 8.1.2.1
                    Alright, it's just helping btw.
                    Last edited by Joeteryse; 03-20-2025, 09:46 PM.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    557 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    324 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    101 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    545 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    547 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X