Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator sometimes crashes the program

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

    #16
    I mean that when on the chart is BarCounter indicator that prints bar numbers below bars and this indicator about which is this topic - after some amount of rebuilds of the chart - it crashes. If there is only BarCounter indicator or only this AAASR indicator - no crashes. NT8 have problems processing both of them simultanously on a single chart.

    Comment


      #17
      Hello Pabulon,

      I was assuming you were referring to the Bar Timer indicator included with NinjaTrader.

      If you have a custom indicator you have created or imported, you would need to reduce and debug to identify what specific code is causing the behavior.

      However, it sounds like you may have one script attempting to add drawing objects and one script trying to remove them at the same time.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        It's pretty standard one I would say

        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
        {
            public class BarCounter : Indicator
            {
                private int _barCntr = 3;
                private int _currentHour = 0;
                private bool _colorHourBars = false;
                private bool _colorBar18Blue = false;
                private bool _showOddNumbers = true;
                private bool _showAllNumbers = false;
                private bool _onlyPlotToday = true;
                private Brush _textColorDefinedbyUser = Brushes.Gray;
                private int _pixelsAboveBelowBar = -50;
                private bool _textIsBelowBars = true;
                private int _fontSize = 14;
                SessionIterator _sessionIterator;      
        
                
            
                
                protected override void OnStateChange()
                {
                    
                    if (State == State.Historical)
                    {
                      //stores the sessions once bars are ready, but before OnBarUpdate is called
                      _sessionIterator = new SessionIterator(Bars);
                    }
                    
                      
                    if (State == State.SetDefaults)
                    {
                        Description = @"Labels Bars by number from session start";
                        Name = "BarCounter";
                        Calculate = Calculate.OnBarClose;
                        IsOverlay = true;
                        DisplayInDataBox = false;
                        DrawOnPricePanel = true;
                        //DrawHorizontalGridLines                        = true;
                        //DrawVerticalGridLines                        = false;
                        PaintPriceMarkers = false;
                        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;
                        TextColor = Brushes.Gray;
                    
                    }
                    else if (State == State.Configure)
                    {
                        if (_pixelsAboveBelowBar > 0 && _textIsBelowBars == true)
                            _pixelsAboveBelowBar = _pixelsAboveBelowBar * -1;
                    }
                }
        
        
        
                protected override void OnBarUpdate()
                {
                    if(_onlyPlotToday)
                    {
                        _sessionIterator.GetNextSession(Time[0], true);
                        TimeSpan ts = DateTime.Now - _sessionIterator.ActualTradingDayExchange;
                        if(ts.Days == 0) //is today
                            PlotIndy();
                    }
                    else
                    {
                        PlotIndy();                
                    }
                }
        
                
                private void PlotIndy()
                {
                    double _textYStartingPoint = High[0]; //position text above or below bars
                        if (_textIsBelowBars)
                            _textYStartingPoint = Low[0];            
                    
                    NinjaTrader.Gui.Tools.SimpleFont myFont = new NinjaTrader.Gui.Tools.SimpleFont("Courier New", 14) { Size = _fontSize, Bold = false };
                    
                    if (Bars.IsFirstBarOfSession) //start counting from first bar of session
                    {
                        _barCntr = 1;
                        _currentHour = Time[0].Hour;
                    }
                    else
                        _barCntr++;
        
                    
                    Brush _tmpBrush = _textColorDefinedbyUser;
                    if(_colorHourBars)
                    {
                        if(Time[0].Hour > _currentHour)
                        {
                            _tmpBrush = Brushes.Red;
                            _currentHour = Time[0].Hour;
                        }
                    }
                    
                    if(_colorBar18Blue)
                    {
                        if(_barCntr % 9 == 0)
                        _tmpBrush = Brushes.Red;
                    }
                    
                    if(_showAllNumbers)
                    {
                            Draw.Text(this, "PO"+CurrentBar.ToString(), true, _barCntr.ToString(), 0, _textYStartingPoint, _pixelsAboveBelowBar, _tmpBrush, myFont, TextAlignment.Center, null, null, 1);
                    }
                    else if (_showOddNumbers)
                    {
                        if (_barCntr % 2 != 0) //is odd number
                            Draw.Text(this, "PO"+CurrentBar.ToString(), true, _barCntr.ToString(), 0, _textYStartingPoint, _pixelsAboveBelowBar, _tmpBrush, myFont, TextAlignment.Center, null, null, 1);
                    }
                    else
                    {
                        if (_barCntr % 3 == 0) //is even number
                            Draw.Text(this, "PO"+CurrentBar.ToString(), true, _barCntr.ToString(), 0, _textYStartingPoint, _pixelsAboveBelowBar, _tmpBrush, myFont, TextAlignment.Center, null, null, 1);
                    }
                    
                }
                
                
                #region Properties
                
                [NinjaScriptProperty]
                [Display(Name = "OnlyPlotToday", Description = "Plot Today Only", Order = 1, GroupName = "Visual")]
                public bool OnlyPlotToday
                {
                    get { return _onlyPlotToday; }
                    set { _onlyPlotToday = value; }
                }
                
                [NinjaScriptProperty]
                [Display(Name = "ShowOddNumbers", Description = "Show Odd or Even Numbers?", Order = 2, GroupName = "Visual")]
                public bool ShowOddNumbers
                {
                    get { return _showOddNumbers; }
                    set { _showOddNumbers = value; }
                }
                
                [NinjaScriptProperty]
                [Display(Name = "ShowAllNumbers", Description = "Show All Bar Numbers?", Order = 3, GroupName = "Visual")]
                public bool ShowAllNumbers
                {
                    get { return _showAllNumbers; }
                    set { _showAllNumbers = value; }
                }
        
                [NinjaScriptProperty]
                [XmlIgnore]
                [Display(Name = "TextColor", Description = "Text Color ", Order = 4, GroupName = "Visual")]
                public Brush TextColor
                {
                    get { return _textColorDefinedbyUser; }
                    set { _textColorDefinedbyUser = value; }
                }
        
                [Range(4, 40)]
                [NinjaScriptProperty]
                [Display(Name = "TextFontSize", Description = "Text Font Size", Order = 5, GroupName = "Visual")]
                public int TextFontSize
                {
                    get { return _fontSize; }
                    set { _fontSize = value; }
                }
        
                [Browsable(false)]
                public string TextColorSerializable
                {
                    get { return Serialize.BrushToString(TextColor); }
                    set { TextColor = Serialize.StringToBrush(value); }
                }
        
                [Range(0, 2000)]
                [NinjaScriptProperty]
                [Display(Name = "PixelsAboveBelow", Description = "Text Offset in Pixels from Bar", Order = 6, GroupName = "Visual")]
                public int PixelsAboveBelow
                {
                    get { return Math.Abs(_pixelsAboveBelowBar); }
                    set { _pixelsAboveBelowBar = value; }
                }
        
                [NinjaScriptProperty]
                [Display(Name = "TextIsBelowBars", Description = "Display Text Above/Below Bars", Order = 7, GroupName = "Visual")]
                public bool TextIsBelowBars
                {
                    get { return _textIsBelowBars; }
                    set { _textIsBelowBars = value; }
                }
                
                [NinjaScriptProperty]
                [Display(Name = "ColorHourBars", Description = "Display Text Above/Below Bars", Order = 8, GroupName = "Visual")]
                public bool ColorHourBars
                {
                    get { return _colorHourBars; }
                    set { _colorHourBars = value; }
                }
        
                [NinjaScriptProperty]
                [Display(Name = "ColorBar18Blue", Description = "Display Text Above/Below Bars", Order = 9, GroupName = "Visual")]
                public bool ColorBar18Blue
                {
                    get { return _colorBar18Blue; }
                    set { _colorBar18Blue = value; }
                }
                
        
                #endregion
            }
        }​

        Comment


          #19
          Hello Pabulon,

          Reduce and debug.

          Comment out code in your script. Confirm the behavior stops. Uncomment one line at at time until the behavior returns.

          What is the specific line of code that is causing the behavior?
          Chelsea B.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X