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!
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
NinjaTrader
Custom Bar Type Caching
Collapse
X
-
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? -
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.
-
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
-
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
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by chbruno, 04-24-2024, 04:10 PM
|
2 responses
46 views
0 likes
|
Last Post
by chbruno
Today, 01:15 PM
|
||
Started by WHICKED, Today, 12:45 PM
|
1 response
10 views
0 likes
|
Last Post Today, 01:08 PM | ||
Started by samish18, Today, 01:01 PM
|
0 responses
5 views
0 likes
|
Last Post
by samish18
Today, 01:01 PM
|
||
Started by WHICKED, Today, 12:56 PM
|
1 response
8 views
0 likes
|
Last Post Today, 01:17 PM | ||
Started by Spiderbird, Today, 12:15 PM
|
2 responses
11 views
0 likes
|
Last Post
by Spiderbird
Today, 12:48 PM
|
Comment