BarsType.Add method - how to always detect if (bars.Count == 0)? - NinjaTrader Programming | futures io social day trading
futures io futures trading

BarsType.Add method - how to always detect if (bars.Count == 0)?
Updated: Views / Replies:2,207 / 2
Created: by jdfagan Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 100,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Thread Tools Search this Thread

BarsType.Add method - how to always detect if (bars.Count == 0)?

  #1 (permalink)
Elite Member
Pacifica, CA
Futures Experience: Advanced
Platform: AmiBroker, TradeStation, NinjaTrader
Broker/Data: Options House
Favorite Futures: Futures, Stocks
jdfagan's Avatar
Posts: 34 since Jun 2009
Thanks: 68 given, 42 received

BarsType.Add method - how to always detect if (bars.Count == 0)?

I also posted this question on Ninja boards but wanted to try my luck here too since I know there are some NT7 experienced custom BarsType coders here...

BarsType.Add method - how to always detect if (bars.Count == 0)? - NinjaTrader Support Forum

I know that this is unsupported by NinjaTrader team, but if NT support can provide any help/hints, it would be appreciated as I'm trying to get some custom bar type code working in NT7. Otherwise, other NT7 custom bar type coders out there, if you have any ideas I'd love to hear them.

So, I'm getting some inconsistent behavior on always being able to reliably detect that bars.Count == 0 from within BarsType.Add method. I had assumed that I would get this if block to always enter per reloading or just loading of a chart. But It seems I can only get it to happen once (perhaps once per from/to combination, not sure yet what drives NT7 calling the Add method - I assumed per tick fed into my chart). For example, after compiling a new variation of my bars type, restarting NT7, and loading up exact same chart with same from/to periods, the bars.Count is automagically greater than 0 to my surprise already (as if the prior NT7 run has cached the generated bars and is not re-calculating them with potentially updated logic of my custom bar type code).

If it is due to cache, I can see that as beneficial for 99.99% of time, except when you are trying to debug your own bars type code and thus alter logic from run to run
Please register on to view futures trading content such as post attachment(s), image(s), and screenshot(s).
. So, if I'm hitting a caching issue, how can I work around it so that after I restart Ninja in between changes to my custom bars type code, it will always hit the bars.Count == 0 logic condition?

Or is there a better way to detect the very first tick from a chart that I want to *ALWAYS* detect for my Tick driven custom bar type within the Add method so I can properly initialize my chart building process?

Here's snippet of code for example - I use Trace.WriteLine (i.e., using System.Diagnostics) so that you can trace code paths within Ninja's trace log files:

public override void Add(Data.Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isRealtime) {
    Trace.WriteLine(String.Format(">>>> bars.Count = {0}", bars.Count));
    if (bars.Count == 0) {
        Trace.WriteLine(">>>> building first bar in chart");
        AddBar(bars, open, high, low, close, time, volume, isRealtime);
    } else {
        Bar bar = (Bar)bars.Get(bars.Count - 1);

Reply With Quote
The following user says Thank You to jdfagan for this post:
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

  #3 (permalink)
Elite Member
Pacifica, CA
Futures Experience: Advanced
Platform: AmiBroker, TradeStation, NinjaTrader
Broker/Data: Options House
Favorite Futures: Futures, Stocks
jdfagan's Avatar
Posts: 34 since Jun 2009
Thanks: 68 given, 42 received

My problem has been resolved over on Ninja forum. In a nutshell, to solve caching issue so that bars.Count == 0 is detected again, you'll need to clear out your database cache for this custom bar type which lives in NinjaTrader 7\db\cache\<SessionTemplate>\[tick|minute]\<Symbol XX-XX>\<CustomBarType>*.ntd

To do this properly, its easiest just to blow away the <SessionTemplate> folder living under db\cache. Or you can try to surgically remove specific *.ntd files appropriate for your debugging session with your custom bar types.

where <SessionTemplate> refers to template for instrument you tested against - for example, "Eurex Equity Index Futures.Pacific Standard Time".

where <Symbol XX-XX> is specific contract of futures symbol - for example, "ES 09-10"

where <CustomBarType> is one of following Bar Types: Final0, Final1, Final2, Final3, Final4, Custom0, Custom1, Custom2, Custom3, Custom4, Custom5, Custom6, Custom7, Custom8, Custom9

Reply With Quote
The following 7 users say Thank You to jdfagan for this post:


futures io > > > > > BarsType.Add method - how to always detect if (bars.Count == 0)?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Upcoming Webinars and Events (4:30PM ET unless noted)

July Journal Challenge - $500 in Amazon Gift Cards!


AXESS Trader: Powerful Cloud Based Trading Platform w/GFF Brokers

Jul 17

TBA: FuturesTrader71 w/Morad Askar

Elite only

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader 7 List of used BarsType base(PeriodType.?) zacharydw00 NinjaTrader Programming 13 December 16th, 2015 12:59 PM
Debugging a BarsType help zacharydw00 NinjaTrader Programming 13 November 20th, 2014 01:51 AM
Momentum BarsType (NT7) eman The Elite Circle 308 June 24th, 2014 11:52 AM
how to count in nt7 the number of bars that have closed? anniebee321 NinjaTrader 9 April 26th, 2011 11:27 AM
Slightly Different - Detect Chop - Trader.Jon NinjaTrader Programming 1 August 30th, 2010 12:49 PM

All times are GMT -4. The time now is 10:35 AM. (this page content is cached, log in for real-time version)

Copyright © 2018 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432,
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2018-07-20 in 0.10 seconds with 14 queries on phoenix