• 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

Custom Bar Type Caching

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

    Custom Bar Type Caching

    I am currently developing a Custom Range Bar Type that has a dynamic range value based on user inputs. The Range calculation is based on a underlying time based set of bars that are built internally. When I close NT and reopen it, the cached bar values are loaded but the underlying time based bars are not which throws off the dynamic range calculation going forward. Is there a way to ignore caching for a Custom Bar Type or a way to force reloading of all historical data?

    #2
    Hello los1440,

    Thank you for your post and welcome to the NinjaTrader Support Forum!

    I am not sure of the complexity in the code but what you describe would not be expected. Can you attach the bars type to your response?

    You can find the file under Documents\NinjaTrader 8\bin\Custom\BarsTypes.

    I look forward to your response.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Unfortunately I cannot attach all of the code because it is one of the products my company offers to clients. I can say that I need specific number of the underlying minute data bars to calculate the dynamic range I use in the custom bar type. Is there a way to make sure that at least that enough data is loaded to ensure enough time bars can be built from the tick data?

      Comment


        #4
        Hello los1440,

        Thank you for your response.

        So the bars type runs on tick data and time based data as well?

        How are you achieving this in the code of the bars type?

        I look forward to your response.
        Patrick H.NinjaTrader Customer Service

        Comment


          #5
          One of the user inputs is a minute length that is used build the underlying minute bars from the input tick data. So we build bars starting with the first tick's time stamp and increment by the input value. So if the user puts in 10 as the input value the code builds time based bars from the input tick data at 10 minute intervals. The first tick to come in sets the first time based bars time stamp then we add x minutes to that value and continue to update using the tick data that comes in until the time stamp of the tick that is being processed is greater than the prior bar's time stamp plus x minutes. I don't think this will give our core logic away so I will post how it is achieved below:

          if(this.SurrogateBars == null)
          {
          int numBarsInDay = (int) ((1440.0 / (double)this.LookBackBars) + 0.5);
          this.LookBackBars = Math.Max(this.LookBackBars,numBarsInDay);

          int numBarsInTwoDays = (int) (numBarsInDay * 2);
          this.RecalcBars = Math.Min(this.RecalcBars,numBarsInTwoDays);

          this.MinTimeSecondsSpan = new TimeSpan(0,0,0,(int)bars.BarsPeriod.Value2);

          SurrogateBars =
          new Bars(
          bars.Instrument,
          new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = (int)bars.BarsPeriod.Value , MarketDataType = MarketDataType.Last},
          bars.FromDate.Subtract(new TimeSpan(0, 0, this.LookBackBars * (int)bars.BarsPeriod.Value, 0)),
          bars.ToDate,
          bars.TradingHours,
          bars.IsSplitAdjusted,
          bars.IsDividendAdjusted,
          bars.IsRolloverAdjusted);

          DateTime nextSessionStart = SessionIterator.ActualSessionBegin;
          AddBar(SurrogateBars, open, high, low, close, TimeToBarTime(bars, time, new DateTime(nextSessionStart.Year, nextSessionStart.Month, nextSessionStart.Day, nextSessionStart.Hour, nextSessionStart.Minute, 0), SurrogateBars.BarsPeriod.Value * 60), volume);


          this.XrangeCalcBar = 0;
          }
          else
          {
          int value = SurrogateBars.BarsPeriod.Value;
          DateTime curTime = SurrogateBars.LastBarTime;

          if ((value > 1 && time < curTime.AddMinutes(value))
          || (value == 1 && time <= curTime.AddMinutes(value)))
          {
          UpdateBar(SurrogateBars, high, low, close, new DateTime(curTime.Year, curTime.Month, curTime.Day, curTime.Hour, curTime.Minute, 0), volume);
          }
          else
          {
          AddBar(SurrogateBars, open, high, low, close, time, volume);
          }
          }
          Last edited by los1440; 08-11-2017, 12:53 PM.

          Comment


            #6
            Hello los1440,

            Thank you for your patience.

            There is no supported means to create a new Bars object in the BarsType. Are you not using BaseBarsPeriodType as it is already Tick?

            I look forward to assisting you further.
            Patrick H.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Duval, Today, 08:38 AM
            0 responses
            10 views
            0 likes
            Last Post Duval
            by Duval
             
            Started by i2w8am9ii2, 02-13-2019, 04:28 PM
            7 responses
            62 views
            0 likes
            Last Post sledge
            by sledge
             
            Started by woodyfox, Yesterday, 08:33 PM
            0 responses
            8 views
            0 likes
            Last Post woodyfox  
            Started by rblunsom, Yesterday, 11:19 AM
            2 responses
            31 views
            0 likes
            Last Post guidoisot  
            Started by drewski1980, Yesterday, 02:38 PM
            1 response
            24 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X