Thanks to RJay and eDanny for adding their contributions here. It gave me a better understanding of what is going on.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Last/First tick of volume bar changed in V7
Collapse
X
-
Well then I guess I am paying the price for coming late to the NT7 party. I did not see any restriction on using FirstTickOfBar outside of OnBarUpdate in the NT6 Help Guide, so I am surprised to see it in NT7. It appears others who are a lot more experienced with this stuff than I am failed to convince NT that a valid first tick indicator in OnMarketData was needed, so I won't ask you to go down that road again.Originally posted by NinjaTrader_Josh View Post
Thanks to RJay and eDanny for adding their contributions here. It gave me a better understanding of what is going on.
-
Possible solution- Is it reliable?
Given that FirstTickOfBar cannot be used in OnMarketData, I looked for an alternative. I don't know if it is universally valid, but it seems to be a simple fix for my indicator, at least for the chart types and parameters I use. Since every tick triggers OnMarketData at some point, and NT has a Bars.TickCount (hoping of course that NT is updating Bars.TickCount before OnMarketData gets triggered; it appears to be working that way), I have replacedwithCode:if (FirstTickOfBar)
I do nothing in OnBarUpdate. All my processing is done in OnMarketData. As before in my original indicator, I compare the volume of the tick corresponding to this condition being true to the bar volume (Volume[0], which also seems to be reliably updating prior to the OnMarketData trigger). When the tick volume is bigger than the bar volume, I know that the tick straddles the bar boundaries and I split the tick between the two bars.Code:if (Bars.TickCount == 1)
This may be an imperfect substitute for a true first tick of bar indicator (OR could this be it?) that will work in OnMarketData, but for the times of day and bar intervals that are of interest to me, it seems to be working well so far. Does anyone see a problem with this?Last edited by HNWtrader; 12-10-2010, 03:06 PM.
Comment
-
if(BarID != CurrentBar)
{
bidsumUp = 0;
asksumUp = 0;
totalaskvol = 0;
totalbidvol = 0;
BarID = CurrentBar;
}
Comment
-
From the NT7 Guide, CurrentBar looks like it is connected to OnBarUpdateOriginally posted by rt6176 View Postif(BarID != CurrentBar)
{
bidsumUp = 0;
asksumUp = 0;
totalaskvol = 0;
totalbidvol = 0;
BarID = CurrentBar;
}
I suspect it could have the same problem as FirstTickOfBar. I did not examine it per se, but I do know from my earlier observations that a bar does not even appear on my time based charts until the second tick (based on Time and Sales) of the bar is processed. So I don't see why there would be a difference between BarID and CurrentBar on the first tick of a bar if examined within OnMarketData where I need to do my processing. But there is a lot of this NT stuff that is still a mystery to me. I certainly don't know much about it.A number representing the current bar in a Bars object that the OnBarUpdate() method in an indicator or strategy is currently processing. For example, if a chart has 100 bars of data, the very first bar of the chart (left most bar) will be number 0 (zero) and each subsequent bar from left to right is incremented by 1.
In some of the posts that you linked you talk about having to save the previous tick values to be processed later. I don't know if you still have to do that, but I don't think there is any need to do it with "if (Bars.TickCount == 1)" because it gets me directly to the first tick of the bar for processing, perhaps even before the bar appears on the chart. I have no idea what NT7 will do if there is a bar with only one tick, but I am never interested in such events.
What I did was to change my test indicator to read Volume[0] in OnBarUpdate, and OnMarketdata. They are indeed not the same, with the reading from OnMarketData leading the reading from OnBarUpdate by 1 tick in NT7.
I looked at this
and later changed "FirstTickOfBar" to "Bars.TickCount == 1". Either way, you see that the volumes from the two methods are not the same. With "if (Bars.TickCount == 1)" you see that at count = 0 (when TickCount = 1), barVolumeData is less than barVolumeDataOld (and is equal to volume on time based charts and probably every other type besides volume) as you would expect if the new bar had opened. But barVolumeBar was still larger than barVolumeBarOld. When I changed the "if" in my original indicator, and moved a few lines from OnBarUpdate to OnMarketData it appeared to solve my problem. I have not yet made the change in my NT6.5 version, but I expect it will work there as well. As long as it keeps working for me, I will stick with it. If not, I will see if using CurrentBar will help me.Code:protected override void OnBarUpdate() { barVolumeBarOld = barVolumeBar; barVolumeBar = (long) Volume[0]; } protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Ask) { askPrice = e.Price; return; } else if (e.MarketDataType == MarketDataType.Bid) { bidPrice = e.Price; return; } else if (e.MarketDataType != MarketDataType.Last || ChartControl == null || askPrice == 0 || bidPrice == 0) return; barVolumeDataOld = barVolumeData; barVolumeData = (long) Volume[0]; volume = e.Volume; price = e.Price; count += 1; if (count < 3) Print ("("+Bars.Period+") " + price + " " + volume + " " + barVolumeBarOld + " " + barVolumeBar + " " + barVolumeDataOld + " " + barVolumeData + " count " + count + " TickCount " + Bars.TickCount); if(FirstTickOfBar) { count = 0; Print (""); Print ("("+Bars.Period+") " + price + " " + volume + " " + barVolumeBarOld + " " + barVolumeBar + " " + barVolumeDataOld + " " + barVolumeData + " count " + count + " TickCount " + Bars.TickCount); } }
Thanks again for your input.Last edited by HNWtrader; 12-11-2010, 10:19 AM.
Comment
-
HNWtrader,
I do not foresee issues with your approach at this point in time except the missing Bars null reference check you should be using when utilizing Bars.TickCount.
Please be sure to check if (Bars != null) before accessing Bars.TickCount outside of OnBarUpdate().Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
579 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
334 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
101 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
551 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment