NexusFi: Find Your Edge


Home Menu

 





Anyone have any hints for optimizing C# code?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Zondor with 20 posts (21 thanks)
    2. looks_two ZTR with 13 posts (0 thanks)
    3. looks_3 Richard with 11 posts (20 thanks)
    4. looks_4 gomi with 7 posts (15 thanks)
      Best Posters
    1. looks_one Fat Tails with 2.6 thanks per post
    2. looks_two gomi with 2.1 thanks per post
    3. looks_3 Richard with 1.8 thanks per post
    4. looks_4 Zondor with 1.1 thanks per post
    1. trending_up 48,397 views
    2. thumb_up 108 thanks given
    3. group 39 followers
    1. forum 111 posts
    2. attach_file 13 attachments




 
Search this Thread

Anyone have any hints for optimizing C# code?

  #71 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505

Did you try using the "Display update interval" in NT ?
It's 0.5 sec by default but you can increase it.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
ZombieSqueeze
Platforms and Indicators
The choice of instruments to trade
Psychology and Money Management
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Diary of a simple price action trader
20 thanks
My NQ Trading Journal
19 thanks
Just another trading journal: PA, Wyckoff & Trends
17 thanks
Tao te Trade: way of the WLD
13 thanks
Daytrading ES & NQ
9 thanks
  #72 (permalink)
 baruchs 
Israel
 
Experience: Intermediate
Platform: NinjaTrader
Broker: pfg
Trading: eminis
Posts: 323 since Jun 2009

"Display update interval" has nothing to do with strategies.

Baruch

Reply With Quote
  #73 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731


Here is an indicator that uses optimization techniques including predefined instances of external indicators and minimization of the number of calls to the MIN and MAX indicators.

As a result, this indicator loads and refreshes super fast.

Thanks again to Richard Todd for explaining the how and why of these techniques.

I hope that some of you will take the time to look at this code and use these techniques in your own work.





Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #74 (permalink)
 
NinjaTrader's Avatar
 NinjaTrader  NinjaTrader is an official Site Sponsor
Site Sponsor

Web: NinjaTrader
AMA: Ask Me Anything
Webinars: NinjaTrader Webinars
Elite offer: Click here
 
Posts: 1,713 since May 2010
Thanks Given: 203
Thanks Received: 2,686


Zondor View Post
Here is an indicator that uses optimization techniques including predefined instances of external indicators and minimization of the number of calls to the MIN and MAX indicators.

As a result, this indicator loads and refreshes super fast.

Thanks again to Richard Todd for explaining the how and why of these techniques.

I hope that some of you will take the time to look at this code and use these techniques in your own work.





FYI

Our MIN/MAX indicators have been re-written in NT7 Beta 17. There is a known bug with this that is resolved for Beta 18. Point being, no need to roll your own MIN/MAX functions. We are also going through all our system indicators to see if we can make some further improvements where it would make a difference.

Follow me on Twitter Reply With Quote
  #75 (permalink)
 
ZTR's Avatar
 ZTR 
 
Experience: Advanced
Platform: NinjaTrader7
Broker: Mirus RCG/Zen-Fire
Trading: CL & 6e, looking at ES, ZB and AU again.
Posts: 2,096 since Nov 2009
Thanks Given: 1,099
Thanks Received: 1,393

Thank you. As I just can't click a button to say this in this form.

R.I.P. Andy Zektzer (ZTR), 1960-2010.
Please visit this thread for more information.
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #76 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

In Double Stochastics Optimized (DSCO), I did two things to reduce the number of times that the MIN and MAX functions would be called in the first place. Reason: these functions do loop processing, so are expensive to run.
  • Made sure that each one could be called no more than once per bar, on FirstTickOfBar.
  • Made sure that even then, each one would be called only when the item last removed from the series, or the item most recently added to the series, could have an effect on what the MIN or MAX indicator would return.
Then, I moved the code from the MIN and MAX indicators into the DSCO indicator itself. I used the same code Ninja used in the original MIN and MAX indicators.

I did this based on the theory that calling a private function might be more efficient than calling an external indicator, however I am not sure about that.

There is a tremendous decrease in loading and refresh time vs. the @DoubleStochastics indicator. I think it's mostly because the number of executions of the MIN and MAX loops has been reduced by a couple of orders of magnitude.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #77 (permalink)
 
aslan's Avatar
 aslan 
Madison, WI
 
Experience: Advanced
Platform: ALT
Trading: ES
Posts: 625 since Jan 2010
Thanks Given: 356
Thanks Received: 1,127


Zondor View Post
I moved the code from the MIN and MAX indicators into the DSCO indicator itself.

Exactly! All of the nested stuff makes it easy to write code, but you pay a price. The built in stuff makes it easy to get up and running and try things out. Once you know it is working though, you can go back and optimize it greatly, if it is really needed.

I don't really use indicators anymore, but when I did, I had coded most of my indicators to remove all of the nested stuff (especially the trivial stuff like MIN/MAX).

Reply With Quote
  #78 (permalink)
 fluxsmith 
Santa Maria
 
Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker: Mirus/Zen-Fire
Trading: ES
Posts: 290 since May 2010
Thanks Given: 97
Thanks Received: 322


Zondor View Post
... and minimization of the number of calls to the MIN and MAX indicators.

As 'Ninjatrader' stated, MIN and MAX iterating when not required is fixed in b18. As I see it the two biggest efficiency problems are iteration and memory consumption. I just posted jhlMIN and jhlMAX which when used in building other indicators and not displayed have memory overhead of 8 * n + 16, vs. I believe over 2K for the standard implementations.



Visit my NexusFi Trade Journal Reply With Quote
  #79 (permalink)
 
Zondor's Avatar
 Zondor 
Portland Oregon, United States
 
Experience: Beginner
Platform: NinjatraderŽ
Broker: CQG, Kinetick
Trading: Gameplay KlownbineŽ Trading of Globex
Posts: 1,333 since Jul 2009
Thanks Given: 1,246
Thanks Received: 2,731

Post #70 in this thread is a perfect example of what not to do. The writer, xxxx72, talks about his programming background, his expert observations regarding NT7, and his scheme to reduce CPU load by skipping OnBarUpdate cycles.

However he failed to correct some extremely obvious and totally ridiculous features of the original code that were the real causes of the poor performance. Adding sampling of intrabar ticks while ignoring the deficiencies of the bar update code is a wonderful example of putting lipstick on a pig.

Here are the major problems:
  • Variables that only need to be calculated once (ONCE, not once per bar) are being calculated on every tick. These variables retain constant values over the entire life span of each instance of the indicator.
  • Variables that only need to be calculated once per bar are also being calculated on every tick. Avoiding that situation is why God gave us the if(FirstTickOfBar) condition.

These problems were a cinch to fix. I guess you have to be a non-programmer like me to notice things like that. C'mon guys, this is inexcusable.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #80 (permalink)
 gomi 
Paris
Market Wizard
 
Experience: None
Platform: NinjaTrader
Posts: 1,270 since Oct 2009
Thanks Given: 282
Thanks Received: 4,505


Just a remark if lots of divisions are involved : remember on a pure performance perspective that division takes much longer than multiplication.

So if you have lost of divisions by a rarely changing x, it's much faster to compute invx=1/x once, and perform multiplications by invx rather than divisions by x.

Reply With Quote
Thanked by:




Last Updated on December 24, 2015


© 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