NexusFi: Find Your Edge


Home Menu

 





Indicator performance bottleneck


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Adamus with 8 posts (1 thanks)
    2. looks_two ratfink with 6 posts (3 thanks)
    3. looks_3 cory with 5 posts (3 thanks)
    4. looks_4 Koepisch with 2 posts (1 thanks)
      Best Posters
    1. looks_one Zondor with 1 thanks per post
    2. looks_two cory with 0.6 thanks per post
    3. looks_3 ratfink with 0.5 thanks per post
    4. looks_4 Adamus with 0.1 thanks per post
    1. trending_up 6,857 views
    2. thumb_up 9 thanks given
    3. group 4 followers
    1. forum 24 posts
    2. attach_file 1 attachments




 
Search this Thread

Indicator performance bottleneck

  #1 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

I wrote an indicator to display support and resistance levels and a few other types of horizontal lines on the chart. It's got pretty complex but that's not to say that it's necessarily a pile of spaghetti - I've started from scratch on a couple of occasions when I've found that the design I had was no longer working.

At this point the indicator that does everything required of it finally, after months of work, but it's got a bad performance problem in that the time to process each historical bar creeps up steadily, making it a pain to load more than about 1500 bars (less 3 days on a 3-min chart), which is stifling my ability to use the indicator to do historical research on the setups I use it for.

I log the time each OnBarUpdate takes. It starts off at 20 millisecs for each OBU and varies around 20 ms, but every 10 or 20 bars it increases by roughly 10 ms. After about 1000 bars it gets up to over 100 ms per OBU. That's like a second for every ten bars, so another day (480 bars) takes almost a minute and then longer and longer.

Despite knowing the indi inside out, I don't really know where to look to see what is causing the problem. I'm not a C# expert so I don't know what the expensive operations are in the code. What foxes me is that I can see from my logging that the indicator can have nothing more to do from one bar to the next over perhaps 100 bars, but the performance degrades anyway.

A few of the things I'm doing that might be causing problems are:
  • using several lists and searching them with delegate/predicate methods
  • using dictionaries in the same way
  • instantiating new objects a lot
  • these objects are based on a class with 2 subclasses, so lots of inheritance going on
  • using multiple time-frames
  • pre-loading data myself with code using GetBars() (this is quick but I thought it might have unknown side-effects)

That list represents my ignorance of C# rather than my insightful experience. Here's what it's doing:



I can post more info, data, logs, whatever - if any C# coders out there have come across this sort of unidentifiable bottle-neck before, I'd love to hear about it and perhaps get some tips on where to investigate.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
Exit Strategy
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
26 thanks
Just another trading journal: PA, Wyckoff & Trends
23 thanks
Tao te Trade: way of the WLD
20 thanks
My NQ Trading Journal
19 thanks
HumbleTraders next chapter
9 thanks
  #3 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


Just sounds like you need to work out a lot more clearly what it needs to do, rather than what it is doing. I can offer speed-up tips, but to be honest you want to be in the micro-second ranges at worst anyway, so I'm guessing at this stage it's orders of magnitude too slow and clearly running geometrically or exponentially so needs a major redesign. All the bullet points you mention are found in many unwieldy OO implementations, I suggest you do some pondering and look for some KISS approaches instead.

And check for obvious no-no's like redrawing every Ninja rectangle from the beginning of time on every tick and such like....

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #4 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789


ratfink View Post
Just sounds like you need to work out a lot more clearly what it needs to do, rather than what it is doing. I can offer speed-up tips, but to be honest you want to be in the micro-second ranges at worst anyway, so I'm guessing at this stage it's orders of magnitude too slow and clearly running geometrically or exponentially so needs a major redesign. All the bullet points you mention are found in many unwieldy OO implementations, I suggest you do some pondering and look for some KISS approaches instead.

And check for obvious no-no's like redrawing every Ninja rectangle from the beginning of time on every tick and such like....

OK I can see you come from the kill it fast and kill it hard school of software development

However the Plot is fine. I've got good durations for each call to Plot(). It's just historical bar processing.

In my defence though, the complexity of the indicator is necessary to keep the visual display on the chart simple, e.g. if I've got 5 lines across 10 points, it'll merge them so you see one zone on the chart, not 5 clustered lines. But I will put my mind to it on how to KISS it. I don't want to be guilty of trying to justify a pile of horseshit.

Another thing I just discovered: the bar update duration drops back down to sub-millisecond levels once it starts processing live bars.

Why? What is the difference between historical and live bars OnBarUpdates?

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 Koepisch 
@ Germany
 
Experience: Beginner
Platform: NinjaTrader
Broker: Mirus Futures/Zen-Fire
Trading: FDAX
Posts: 569 since Nov 2011
Thanks Given: 440
Thanks Received: 518

@Adamus It's impossible to help you out without looking at the source codes. You can check if your code iterates thru the whole set of historical bars at new bar arrival (include some function loop counter). Have you used the debugger to resolve your problems?

Reply With Quote
Thanked by:
  #6 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


Adamus View Post
OK I can see you come from the kill it fast and kill it hard school of software development

You bet. In 40 years I have met many writers of correct software but, since OO and Ghz CPUs, a lot less writers of (correct && efficient) software.

On the other hand you may just be unlucky at this stage and have a simple gotcha in there that just needs hunting down. It sounds like you know what you are doing, maybe just need to dig deeper. My first thought was that you are exponentially processing all bars on every tick or something, but I'm only guessing at a distance so can't really help that much.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425


Adamus View Post
Why? What is the difference between historical and live bars OnBarUpdates?

There are several, but one that comes to mind is the drawing of off-screen graphical artefacts, Ninja doesn't seem too good at clipping, e.g. particularly of rectangles/triangles, which is why I mentioned them. You can speed up a lot of things by not drawing unnecessarily, but it is always worth proving what is taking the time first just by commenting out calls, etc. Lots of red-herrings to find and eliminate when you really start to run a speed-up exercise! It can always be our own code or just unrealistic expectations of somebody else's.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #8 (permalink)
 
ratfink's Avatar
 ratfink 
Birmingham UK
Market Wizard
 
Experience: Intermediate
Platform: NinjaTrader
Broker: TST/Rithmic
Trading: YM/Gold
Posts: 3,633 since Dec 2012
Thanks Given: 17,423
Thanks Received: 8,425

Just another quick point, getting things up into the milli-second rather than micro-second levels usually takes memory or even hard page faults to become an issue, have you eliminated that side of things? (i.e. the TM is showing (100/number-of-cores)% flat-out for Ninja and no hard faults so it is all cpu). Would be unusual but not unknown, just depends what you are doing.

Travel Well
Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 
cory's Avatar
 cory 
virginia
 
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090

set a calculation kill switch on after calculation on history data is done.

Reply With Quote
Thanked by:
  #10 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789



Koepisch View Post
@Adamus It's impossible to help you out without looking at the source codes. You can check if your code iterates thru the whole set of historical bars at new bar arrival (include some function loop counter). Have you used the debugger to resolve your problems?

Hi Koepisch, good comment, thanks. I shall check while I am going through adding more detailed performance monitoring.

The code runs to 2800 lines. I assume nobody would want to look at it - I can't imagine I'd want to look at somebody else's dogfood. If I'm wrong, I'd gladly attach it - just say the word.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote




Last Updated on December 9, 2013


© 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