• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

BarsTypeSecond Duplicate Not Acting as Expected

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

    BarsTypeSecond Duplicate Not Acting as Expected

    So I am attempting to make some changes to a new second bars type. When I copy the SecondBarsType template from NT8 and simply change the name and update the BarsPeriodType as required it updates on every change in price no matter what the duration is set to.

    For example if I set it up for 100 seconds you would expect the bar to complete every 100 seconds but instead a new one is created on every price change.

    For simplicity sake I have copied the original code for the SecondBarsType with my 2 changes necessary for just changing the name etc.

    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;
    
    #endregion
    
    //This namespace holds Bars types in this folder and is required. Do not change it. 
    namespace NinjaTrader.NinjaScript.BarsTypes
    {
    	public class FXR_SecondFilter : BarsType
    	{
    		public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
    		{
    
    		}
    
    		public override void ApplyDefaultValue(BarsPeriod period)
    		{
    			period.BarsPeriodTypeName = Custom.Resource.BarsPeriodTypeNameSecond;
    			period.Value = 30;
    		}
    
    		public override string ChartLabel(DateTime time)
    		{
    			return time.ToString("HH:mm:ss");
    		}
    
    		public override int GetInitialLookBackDays(BarsPeriod period, TradingHours tradingHours, int barsBack)
    		{ 
    			return (int) Math.Max(1, Math.Ceiling(barsBack / Math.Max(1, 8.0 * 60 * 60 / period.Value)) * 7.0 / 5.0);
    		}
    
    		public override double GetPercentComplete(Bars bars, DateTime now)
    		{
    			return now <= bars.LastBarTime ? 1.0 - (bars.LastBarTime.Subtract(now).TotalSeconds / bars.BarsPeriod.Value) : 1;
    		}
    
    		protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
    		{
    			if (SessionIterator == null)
    				SessionIterator = new SessionIterator(bars);
    
    			if (bars.Count == 0 || time >= bars.LastBarTime)
    			{
    				DateTime barTime = TimeToBarTime(bars, time, isBar);
    				AddBar(bars, open, high, low, close, barTime, volume);
    			}
    			else
    				UpdateBar(bars, high, low, close, bars.LastBarTime, volume);
    		}
    
    		protected override void OnStateChange()
    		{
    			if (State == State.SetDefaults)
    			{
    				// ONLY CHANGES - NEXT 2 LINES - ORIGINAL COMMENTED OUT
    				Name						= "FXR Second Filter"; //Custom.Resource.NinjaScriptBarsTypeSecond;
    				BarsPeriod					= new BarsPeriod{BarsPeriodType = (BarsPeriodType)18,BarsPeriodTypeName = Name};//new BarsPeriod { BarsPeriodType = BarsPeriodType.Second };
    				BuiltFrom					= BarsPeriodType.Tick;
    				DaysToLoad					= 3;
    				IsIntraday					= true;
    			}
    			else if (State == State.Configure)
    			{
    				Name = string.Format("{0}{1}", string.Format(Core.Globals.GeneralOptions.CurrentCulture, Custom.Resource.DataBarsTypeSecond, BarsPeriod.Value), (BarsPeriod.MarketDataType != MarketDataType.Last ? string.Format(" - {0}", Core.Globals.ToLocalizedObject(BarsPeriod.MarketDataType, Core.Globals.GeneralOptions.CurrentUICulture)) : string.Empty));
    
    				Properties.Remove(Properties.Find("BaseBarsPeriodType",			true));
    				Properties.Remove(Properties.Find("BaseBarsPeriodValue",		true));
    				Properties.Remove(Properties.Find("PointAndFigurePriceType",	true));
    				Properties.Remove(Properties.Find("ReversalType",				true));
    				Properties.Remove(Properties.Find("Value2",						true));
    			}
    		}
    
    		private DateTime TimeToBarTime(Bars bars, DateTime time, bool isBar)
    		{
    			if (SessionIterator.IsNewSession(time, isBar))
    				SessionIterator.GetNextSession(time, isBar);
    
    			if (bars.IsResetOnNewTradingDay || !bars.IsResetOnNewTradingDay && bars.Count == 0)
    			{
    				DateTime barTimeStamp = isBar
    					? SessionIterator.ActualSessionBegin.AddSeconds(Math.Ceiling(Math.Ceiling(Math.Max(0, time.Subtract(SessionIterator.ActualSessionBegin).TotalSeconds)) / bars.BarsPeriod.Value) * bars.BarsPeriod.Value)
    					: SessionIterator.ActualSessionBegin.AddSeconds(bars.BarsPeriod.Value + Math.Floor(Math.Floor(Math.Max(0, time.Subtract(SessionIterator.ActualSessionBegin).TotalSeconds)) / bars.BarsPeriod.Value) * bars.BarsPeriod.Value);
    				if (bars.TradingHours.Sessions.Count > 0 && barTimeStamp > SessionIterator.ActualSessionEnd) // Cut last bar in session down to session end on odd session end time
    					barTimeStamp = SessionIterator.ActualSessionEnd;
    				return barTimeStamp;
    			}
    			else
    			{
    				DateTime lastBarTime	= bars.GetTime(bars.Count - 1);
    				DateTime barTimeStamp	= isBar 
    					? lastBarTime.AddSeconds(Math.Ceiling(Math.Ceiling(Math.Max(0, time.Subtract(lastBarTime).TotalSeconds)) / bars.BarsPeriod.Value) * bars.BarsPeriod.Value)
    					: lastBarTime.AddSeconds(bars.BarsPeriod.Value + Math.Floor(Math.Floor(Math.Max(0, time.Subtract(lastBarTime).TotalSeconds)) / bars.BarsPeriod.Value) * bars.BarsPeriod.Value);
    				if (bars.TradingHours.Sessions.Count > 0 && barTimeStamp > SessionIterator.ActualSessionEnd)
    				{
    					DateTime saveActualSessionEnd = SessionIterator.ActualSessionEnd;
    					SessionIterator.GetNextSession(SessionIterator.ActualSessionEnd.AddSeconds(1), isBar);
    					barTimeStamp = SessionIterator.ActualSessionBegin.AddSeconds((int) barTimeStamp.Subtract(saveActualSessionEnd).TotalSeconds);
    				}
    				return barTimeStamp;
    			}
    		}
    	}
    }

    #2
    For example see the two attached images, one of standard 30 second and one with modified 100 second using custom barstype that is copied directly from NT8 SecondBarsType.
    Attached Files

    Comment


      #3
      Hello fxRichard,

      Thank you for writing in.

      I would not expect this behavior to occur. I was able to duplicate this behavior on my end and have submitted a bug report on this matter.

      Please, let us know if we may be of further assistance.
      Zachary G.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_ZacharyG View Post
        Hello fxRichard,

        Thank you for writing in.

        I would not expect this behavior to occur. I was able to duplicate this behavior on my end and have submitted a bug report on this matter.

        Please, let us know if we may be of further assistance.
        Thanks Zachary. What is the usual turnaround on bug fixes? Just trying to get an idea of when we might expect a fix. Thanks.

        Comment


          #5
          Hello fxRichard,

          Unfortunately, I wouldn't be able to provide a time period of how long it may take for bug report fixes to be implemented.
          Zachary G.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_ZacharyG View Post
            Hello fxRichard,

            Unfortunately, I wouldn't be able to provide a time period of how long it may take for bug report fixes to be implemented.
            Thanks Zachary. On a side note I'm simply trying to create a seconds bars type that filters out the fractional pip (5th decimal on EUR/USD). Is there any other possible way to do so until this is fixed as I don't want It to chart fractions of pips but need 5th decimal for other processing in the app etc.

            Comment


              #7
              Hello fxRichard,

              You wouldn't be able to do this from a bar type. The ability to change the pip-size displayed on charts has been removed from NinjaTrader 8, but we do have a feature request with an ID of SFT-607 currently open in regards to this. I would be happy to add your vote to this feature request if you would like me to.
              Zachary G.NinjaTrader Customer Service

              Comment


                #8
                Originally posted by NinjaTrader_ZacharyG View Post
                Hello fxRichard,

                You wouldn't be able to do this from a bar type. The ability to change the pip-size displayed on charts has been removed from NinjaTrader 8, but we do have a feature request with an ID of SFT-607 currently open in regards to this. I would be happy to add your vote to this feature request if you would like me to.
                Thanks Zach, I'm doing something that solves the problem in another bars type for a single tick chart by filtering out the 5th decimal place simply for charting purposes. I needed the same thing to happen on the second and minutes bar type hence why I was trying to copy the SecondBarsType template.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by uiwislth, Yesterday, 11:25 PM
                0 responses
                4 views
                0 likes
                Last Post uiwislth  
                Started by Steve L, Yesterday, 10:04 PM
                0 responses
                3 views
                0 likes
                Last Post Steve L
                by Steve L
                 
                Started by marianfed, Yesterday, 09:47 PM
                0 responses
                4 views
                0 likes
                Last Post marianfed  
                Started by hir04068, Yesterday, 09:29 PM
                0 responses
                2 views
                0 likes
                Last Post hir04068  
                Started by iq200, 03-11-2018, 07:49 PM
                24 responses
                1,021 views
                0 likes
                Last Post mrlucky1x  
                Working...
                X