Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Custom Bartype needs me to select TickReplay

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

    Custom Bartype needs me to select TickReplay

    Hi,

    The tick replay issue , has been solved... However, I get an error on custom bar types I code... I wrote a sample xTick Bar Type which is my test code in which i basically create a tick bar type where I internally count the ticks....but I get a "unable to write cache data error" often when using it...

    Please let me know what I am doing wrong that causes this error...

    Thanks in advance.

    Code is in next post
    Last edited by KhaosTrader; 08-28-2016, 11:53 PM.

    #2
    progress but problems...

    Hi,

    here is code below:

    [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 xTick : BarsType
    {


    private int TickCount=0;

    protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = @"Enter the description for your new custom Bars type here.";
    Name = "xTick";
    BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 15, BarsPeriodTypeName = "xTick", Value = 1 };
    BuiltFrom = BarsPeriodType.Tick;
    DaysToLoad = 5;
    IsIntraday = true;
    }
    else if (State == State.Configure)
    {
    Name = string.Format(Core.Globals.GeneralOptions.CurrentC ulture, Custom.Resource.DataBarsTypeTick, BarsPeriod.Value, (BarsPeriod.MarketDataType != MarketDataType.Last ? string.Format(" - {0}", Core.Globals.ToLocalizedObject(BarsPeriod.MarketDa taType, Core.Globals.GeneralOptions.CurrentUICulture)) : string.Empty));


    Properties.Remove(Properties.Find("BaseBarsPeriodT ype", true));
    Properties.Remove(Properties.Find("BaseBarsPeriodV alue", true));
    Properties.Remove(Properties.Find("PointAndFigureP riceType", true));
    Properties.Remove(Properties.Find("ReversalType", true));
    Properties.Remove(Properties.Find("Value2", true));
    }
    }

    public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
    {
    return 1; //replace with your bars logic
    }

    protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask)
    {



    // priceChangeCount < bars.BarsPeriod.Value

    if (SessionIterator == null)
    SessionIterator = new SessionIterator(bars);

    bool isNewSession = SessionIterator.IsNewSession(time, isBar);
    if (isNewSession)
    SessionIterator.GetNextSession(time, isBar);
    if (bars.BarsPeriod.Value == 1)
    {
    AddBar(bars, open, high, low, close, time, volume, bid, ask);
    TickCount=0;
    }
    else if (bars.Count == 0)
    {
    AddBar(bars, open, high, low, close, time, volume);
    TickCount=0;
    }

    else if (bars.Count > 0 && (!bars.IsResetOnNewTradingDay || !isNewSession) && bars.BarsPeriod.Value > 1 && TickCount < bars.BarsPeriod.Value)
    {
    UpdateBar(bars, high, low, close, time, volume);

    TickCount++;


    }
    else
    {
    AddBar(bars, open, high, low, close, time, volume);
    TickCount=0;
    }

    }

    public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
    {
    //replace with any default base period value logic
    }

    public override void ApplyDefaultValue(BarsPeriod period)
    {
    //replace with any default value logic
    }

    public override string ChartLabel(DateTime dateTime)
    {
    return dateTime.ToString("HH:mm:ss");
    }

    public override double GetPercentComplete(Bars bars, DateTime now)
    {
    return 1.0d; //replace with your bar percent logic
    }

    }
    }



    [/CODE]
    Last edited by KhaosTrader; 08-28-2016, 11:52 PM.

    Comment


      #3
      Hello KhaosTrader,

      Thanks for your post.

      What datafeed, instrument and size tick bars are you using?

      If you change the number of days to load to 2 or less, do you get the same or any error message?

      Can you confirm you get the cache error when using tick replay and/or without tick replay?
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        I am using EURGBP, 1440 tick, FXCM datafeed. realtime...Do you get an error on your end?

        Comment


          #5
          Hello KhaosTrader,

          Thanks for your reply.

          Yes, I was getting XML serialization errors which created an unhandled exception.
          Looking through the trace file I see:
          2016-08-29 08:12:25:765 ERROR: Data.Bars.Load7: System.InvalidOperationException: There was an error generating the XML document. ---> System.FieldAccessException: Attempt by method 'Microsoft.Xml.Serialization.GeneratedAssembly.Xml SerializationWriterxTick.Write9_xTick(System.Strin g, System.String, NinjaTrader.NinjaScript.BarsTypes.xTick, Boolean, Boolean)' to access field 'NinjaTrader.NinjaScript.BarsTypes.xTick.TickCount ' failed.

          Try changing from
          private int TickCount=0;
          to
          private int tickCount=0;
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Ok that error was eliminated BUT i decided to just make sure I was able to do something to show that I can manipulate the tick value, so I wrote a line that counted every other tick... Unfortunately, it shows the same tick chart.. so I have no clue why that is... So my questions are..

            1) why cant I use a capital T for my tickCount variable?
            2) why is the code below not showing different bar structure from a standard Tick chart?

            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 xTick : BarsType
            	{
            		
            	
            		private int		tickCount=0;
            		private int   dataCounter = 0;
            		
            		protected override void OnStateChange()
            		{
            			if (State == State.SetDefaults)
            			{
            				Description									= @"Enter the description for your new custom Bars type here.";
            				Name										= "xTick";
            				BarsPeriod									= new BarsPeriod { BarsPeriodType = (BarsPeriodType) 15, BarsPeriodTypeName = "xTick", Value = 1 };
            				BuiltFrom									= BarsPeriodType.Tick;
            				DaysToLoad									= 5;
            				IsIntraday									= true;
            			}
            			else if (State == State.Configure)
            			{
            				//Name = string.Format(Core.Globals.GeneralOptions.CurrentCulture, Custom.Resource.DataBarsTypeTick, BarsPeriod.Value, (BarsPeriod.MarketDataType != MarketDataType.Last ? string.Format(" - {0}", Core.Globals.ToLocalizedObject(BarsPeriod.MarketDataType, Core.Globals.GeneralOptions.CurrentUICulture)) : string.Empty));
            				//Name = string.Format(Core.Globals.GeneralOptions.CurrentCulture, "xTick", BarsPeriod.Value, (BarsPeriod.MarketDataType != MarketDataType.Last ? string.Format(" - {0}", Core.Globals.ToLocalizedObject(BarsPeriod.MarketDataType, Core.Globals.GeneralOptions.CurrentUICulture)) : string.Empty));
            				Name = BarsPeriod.Value + " xTick";
            				
            				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));
            			}		
            		}
            
            		public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack)
            		{
            			return 1; //replace with your bars logic
            		}
            
            		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);
            
            			bool isNewSession = SessionIterator.IsNewSession(time, isBar);
            			if (isNewSession)
            				SessionIterator.GetNextSession(time, isBar);
            			if (bars.BarsPeriod.Value == 1)
            			{
            				AddBar(bars, open, high, low, close, time, volume, bid, ask);
            				tickCount=0;	
            				dataCounter= 0;
            			}
            			else if (bars.Count == 0)
            			{
            				AddBar(bars, open, high, low, close, time, volume);
            				tickCount=0;	
            				dataCounter = 0;
            			}
            
            			else if (bars.Count > 0 && (!bars.IsResetOnNewTradingDay || !isNewSession) && bars.BarsPeriod.Value > 1 && tickCount < bars.BarsPeriod.Value)
            			{
            				UpdateBar(bars, high, low, close, time, volume);
            
            				dataCounter++;
            				if (dataCounter % 2 == 0 ) { tickCount++;}
            					
            				
            			}
            			else
            			{
            				AddBar(bars, open, high, low, close, time, volume); 	
            				tickCount=0;	
            				dataCounter = 0;
            			}
            					
            		}
            
            		public override void ApplyDefaultBasePeriodValue(BarsPeriod period)
            		{
            			//replace with any default base period value logic
            		}
            
            		public override void ApplyDefaultValue(BarsPeriod period)
            		{
            			//replace with any default value logic
            		}
            
            		public override string ChartLabel(DateTime dateTime)
            		{
            			return dateTime.ToString("HH:mm:ss");
            		}
            
            		public override double GetPercentComplete(Bars bars, DateTime now)
            		{
            			return 1.0d; //replace with your bar percent logic
            		}
            
            	}
            }

            Comment


              #7
              Hello KhaosTrader,

              Thanks for your reply.

              I'm not following what you are trying to do here so my response may or may not be helpful.

              TickCount already exists as bars.TickCount (check the tick bar type code). You might be better off using Bars.TickCount http://ninjatrader.com/support/helpG...?tickcount.htm

              If the bar does meets the definition of bars.TickCount < bars.BarsPeriod.Value then the bar is updated otherwise it will be added. Are you wanting to change the tickcount of the bars from other than what is specified in the BasrPeriod.Value? (1440 tick in your recent example)?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Hi,
                I plan to make an algorithm that will utilize tick count and other logic that once satisfied will paint a new bar.

                Before I code my personal algo, I wanted to make sure that i could do a simplistic count of ticks manually, and manipulate the condition that creates a new bar.

                The code which i have posted xTick, as test project, has its own variable called tickCount which actually will count every other tick, and once that sum is greater than the BarsPeriod.Value, it will create a new bar.

                Therefore, the net result of this current test xTick code that I have included should be, assuming a BarPeriod of 1440 , should create a new bar approximately every 2880 ticks. This should render bars differently than a standard Tick Chart that is included as a default bar type in ninjatrader.

                Unfortunately, I am not getting the effect I hoped. The code i submitted here is rendering the same result as a standard Tick Chart.

                Therefore, I am not confident that I am able to create my more unique and sophisticated algorithym at this point, as I cannot even get this simple code to work properly.

                So I am asking, why it doesn't the xTick code that I have posted work properly?
                Last edited by KhaosTrader; 08-29-2016, 01:01 PM.

                Comment


                  #9
                  Hello,

                  Thanks for your reply.

                  I've copied your code and produced a 1440 tick chart with xTick bars and regular tick bars, as you can see they are different.
                  Attached Files
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Apologies, yes I see they are different, somehow I didnt refresh the chart or something, I see that upon updating the bar type code, I must change the tick value to another value and then back again to get it to re-render.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by MarianApalaghiei, Today, 10:49 PM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by love2code2trade, Yesterday, 01:45 PM
                    4 responses
                    28 views
                    0 likes
                    Last Post love2code2trade  
                    Started by funk10101, Today, 09:43 PM
                    0 responses
                    8 views
                    0 likes
                    Last Post funk10101  
                    Started by pkefal, 04-11-2024, 07:39 AM
                    11 responses
                    37 views
                    0 likes
                    Last Post jeronymite  
                    Started by bill2023, Yesterday, 08:51 AM
                    8 responses
                    46 views
                    0 likes
                    Last Post bill2023  
                    Working...
                    X