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

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.

    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.

        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, 01: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.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottWalsh, Today, 04:29 PM
            0 responses
            4 views
            0 likes
            Last Post ScottWalsh  
            Started by rtwave, 04-12-2024, 09:30 AM
            2 responses
            21 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            5 responses
            69 views
            0 likes
            Last Post tsantospinto  
            Started by cre8able, Today, 03:20 PM
            0 responses
            7 views
            0 likes
            Last Post cre8able  
            Started by Fran888, 02-16-2024, 10:48 AM
            3 responses
            49 views
            0 likes
            Last Post Sam2515
            by Sam2515
             
            Working...
            X