NexusFi: Find Your Edge


Home Menu

 





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


Discussion in NinjaTrader

Updated
    1. trending_up 3,140 views
    2. thumb_up 8 thanks given
    3. group 1 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

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

  #1 (permalink)
 
jdfagan's Avatar
 jdfagan 
Pacifica, CA
 
Experience: Advanced
Platform: AmiBroker, TradeStation, NinjaTrader
Broker: Options House
Trading: Futures, Stocks
Posts: 34 since Jun 2009
Thanks Given: 68
Thanks Received: 44

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)? - [AUTOLINK]NinjaTrader[/AUTOLINK] 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 . 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:

 
Code
 
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);
        ...
    }
JD

Follow me on Twitter Started this thread Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
Build trailing stop for micro index(s)
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
59 thanks
Funded Trader platforms
37 thanks
NexusFi site changelog and issues/problem reporting
24 thanks
GFIs1 1 DAX trade per day journal
22 thanks
The Program
19 thanks
  #3 (permalink)
 
jdfagan's Avatar
 jdfagan 
Pacifica, CA
 
Experience: Advanced
Platform: AmiBroker, TradeStation, NinjaTrader
Broker: Options House
Trading: Futures, Stocks
Posts: 34 since Jun 2009
Thanks Given: 68
Thanks Received: 44


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.

Notes:
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

Follow me on Twitter Started this thread Reply With Quote




Last Updated on June 29, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts