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

debugging custom chart type

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

    debugging custom chart type

    Hello,

    I looked around in the forum and on google but have not found a solution for it:

    I work on a custom bar type which I stored in the indicator folder in order to access the code with the Ninjascript editor. After a change of the code I always need to restart the whole Ninjatrader application for seeing the effects of my code changes in the chart. For other Ninjascripts (indicators or strategies) there is the possibility to reload them in the chart.

    Is there any possibility to reload a bar type without closing the whole application?

    As I understood the debugging with e.g. visual studio allows breakpoints in order to analyze the code behaviour. But would this allow me to see the changed bar type in the chart without a restart of NT?

    Many thanks.

    Joerg

    #2
    I have always needed to restart NinjaTrader in order for the changes to get registered to the system.it does not do this automatically by detecting the change. When you restart NinjaTrader it runs through its Custom folder in the Documents and registers any new items and then does an internal compile of those so that when you go to create a chart it loads the chart style for the dropdown.

    Comment


      #3
      Try to import any indicator. This recompile the whole library and the changes in your custom bar type take effect without having to restart Ninja.

      I hope this behavior change in Ninja8. Some of the lucky beta testers could verify this.

      Regards.

      Comment


        #4
        Thank you for your answers.

        @cls71: unfortunately it helps not to recompile during an indicator import. it seems it is the same effect than just compiling in the ninjascript editor. It does not change the chart, created with the custom bar type which I edited.

        @Calonious: Although it was not the answer I hoped for, thanks a lot. For me it also seems there is no chance to avoid a restart of ninjatrader.

        Comment


          #5
          Hello,

          I prepared a code for a custom bar type out of the RangeBarType provided by NinjaTrader in the @BarsType.cs file. I changed some properties and used the Name "RangeMin", which is now shown in the drop-down list of the ChartTypes and the ChartLabel. As far as I know and understand from the BarsTypes provided in @BarsTypes.cs I need to put my bar generation logic in the "public override void Add(Bars bars,...)" section of the code (market red in the code below)?!

          Code:
          #region Using declarations
          using System;
          using System.Collections;
          using System.ComponentModel;
          using System.Text;
          #endregion
          
          // This namespace holds all bars types. Do not change it.
          namespace NinjaTrader.Data
          {
          	/// <summary>
          	/// </summary>
          	public class RangeMinBarsType : BarsType
          	{
          		private static bool  registered = Register(new RangeMinBarsType());
          
          		/// <summary>
          		/// </summary>
          		/// <param name="bars"></param>
          		/// <param name="open"></param>
          		/// <param name="high"></param>
          		/// <param name="low"></param>
          		/// <param name="close"></param>
          		/// <param name="time"></param>
          		/// <param name="volume"></param>
          		/// <param name="isRealtime"></param>
          		public override void Add(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime)
          		{
          
          [COLOR="Red"]// main bar generating code ?![/COLOR]
          [COLOR="Red"]// AddBar()[/COLOR]
          [COLOR="Red"]// UpdateBar()[/COLOR]
          
          		}
          
          public override void ApplyDefaults(Gui.Chart.BarsData barsData)
          		{
          			barsData.DaysBack		= 30;
          			barsData.Period.Value	= 1;
          		}
          
          		/// <summary>
          		/// </summary>
          		public override PeriodType BuiltFrom
          		{
          			get { return PeriodType.Minute; }
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="time"></param>
          		/// <returns></returns>
          		public override string ChartDataBoxDate(DateTime time)
          		{
          			return time.ToString(Cbi.Globals.CurrentCulture.DateTimeFormat.ShortDatePattern);
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="chartControl"></param>
          		/// <param name="time"></param>
          		/// <returns></returns>
          		public override string ChartLabel(Gui.Chart.ChartControl chartControl, DateTime time)
          		{
          			return time.ToString(chartControl.LabelFormatTick, Cbi.Globals.CurrentCulture);
          		}
          
          		/// <summary>
          		/// Here is how you restrict the selectable chart styles by bars type
          		/// </summary>
          		public override Gui.Chart.ChartStyleType[] ChartStyleTypesSupported
          		{
          			get { return new[] { Gui.Chart.ChartStyleType.Box, Gui.Chart.ChartStyleType.CandleStick, Gui.Chart.ChartStyleType.HiLoBars, Gui.Chart.ChartStyleType.LineOnClose, 
          				Gui.Chart.ChartStyleType.OHLC }; }
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <returns></returns>
          		public override object Clone()
          		{
          			return new RangeMinBarsType();
          		}
          
          		/// <summary>
          		/// </summary>
          		public override int DefaultValue
          		{ 
          			get { return 4; }
          		}
          
          		/// <summary>
          		/// </summary>
          		public override string DisplayName
          		{
          			get { return "RangeMin"; }
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="period"></param>
          		/// <param name="barsBack"></param>
          		/// <returns></returns>
          		public override int GetInitialLookBackDays(Period period, int barsBack)
          		{ 
          			return 1;
          		}	
          			
          		/// <summary>
          		/// </summary>
          		public override double GetPercentComplete(Bars bars, DateTime now)
          		{
          			throw new ApplicationException("GetPercentComplete not supported in " + DisplayName);
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="propertyDescriptor"></param>
          		/// <param name="period"></param>
          		/// <param name="attributes"></param>
          		/// <returns></returns>
          		public override PropertyDescriptorCollection GetProperties(PropertyDescriptor propertyDescriptor, Period period, Attribute[] attributes)
          		{
          			PropertyDescriptorCollection properties = base.GetProperties(propertyDescriptor, period, attributes);
          
          			// here is how you remove properties not needed for that particular bars type
          			properties.Remove(properties.Find("BasePeriodType", true));
          			properties.Remove(properties.Find("BasePeriodValue", true));
          			properties.Remove(properties.Find("PointAndFigurePriceType", true));
          			properties.Remove(properties.Find("ReversalType", true));
          			properties.Remove(properties.Find("Value2", true));
          
          			// here is how you change the display name of the property on the properties grid
          			Gui.Design.DisplayNameAttribute.SetDisplayName(properties, "Value", "\r\rValue");
          
          			return properties;
          		}
          
          		/// <summary>
          		/// </summary>
          		public override bool IsIntraday
          		{
          			get { return true; }
          		}
          
          		/// <summary>
          		/// </summary>
          		public RangeMinBarsType() : base(PeriodType.Final1)
          		{
          		}
          
          		/// <summary>
          		/// </summary>
          		/// <param name="period"></param>
          		/// <returns></returns>
          		public override string ToString(Period period)
          		{
          			return string.Format("{0} RangeMin{1}", period.Value, (period.MarketDataType != MarketDataType.Last ? " - " + period.MarketDataType : string.Empty));
          		}
          	}
          
          }

          I like to start from zero and try to implement my custom bar logic step by step. If I plot a chart with this "RangeMin" BarsType it plots bars although the "public override void Add(Bars bars,...)" section is completely empty (pls see the colored bars in the screenshot, the gray bars are plain minute bars).

          How is this possible and how can I avoid it?

          Many thanks.

          Joerg
          Attached Files

          Comment


            #6
            Hello Everyone,

            Just a mention that creating custom bar types for NinjaTrader 7 are not supported by NinjaTrader support and we are not able to assist with this. However, these will be fully supported in NinjaTrader 8.

            I can also confirm that a restart is required when importing a bar type in NT7.

            As a small tip, calling AddBar closes the current bar with the supplied information. UpdateBar does not close the bar but does update the bar with the supplied information.

            This thread will remain open for the community to assist.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Barry Milan, Today, 10:35 PM
            1 response
            8 views
            0 likes
            Last Post NinjaTrader_Manfred  
            Started by WeyldFalcon, 12-10-2020, 06:48 PM
            14 responses
            1,428 views
            0 likes
            Last Post Handclap0241  
            Started by DJ888, Yesterday, 06:09 PM
            2 responses
            9 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by jeronymite, 04-12-2024, 04:26 PM
            3 responses
            40 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Today, 08:51 AM
            2 responses
            16 views
            0 likes
            Last Post bill2023  
            Working...
            X