Anyone have any hints for optimizing C# code? - NinjaTrader Programming | futures io social day trading
futures io futures trading


Anyone have any hints for optimizing C# code?
Updated: Views / Replies:24,834 / 111
Created: by ZTR Attachments:14

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 90,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

Reply
 14  
 
Thread Tools Search this Thread
 

Anyone have any hints for optimizing C# code?

  #71 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,177 since Oct 2009
Thanks: 228 given, 4,097 received

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
 
  #72 (permalink)
Elite Member
Israel
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: pfg
Favorite Futures: eminis
 
Posts: 323 since Jun 2009
Thanks: 6 given, 206 received

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

Baruch

Reply With Quote
 
  #73 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Example of Ninjatrader indicator with optimized code


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.




https://futures.io/free_downloads/vip_elite_circle/505-download.html?view

Reply With Quote
 
  #74 (permalink)
Elite Member
Denver, CO
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: NinjaTrader Brokerage
Favorite Futures: ES
 
NinjaTrader's Avatar
 
Posts: 1,260 since May 2010
Thanks: 153 given, 1,890 received


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.




https://futures.io/free_downloads/vip_elite_circle/505-download.html?view

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.

Reply With Quote
The following 4 users say Thank You to NinjaTrader for this post:
 
  #75 (permalink)
 R.I.P. 1960-2010 
 
Futures Experience: Advanced
Platform: NinjaTrader7
Broker/Data: Mirus RCG/Zen-Fire
Favorite Futures: CL & 6e, looking at ES, ZB and AU again.
 
ZTR's Avatar
 
Posts: 2,099 since Nov 2009
Thanks: 1,104 given, 1,390 received

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.
Reply With Quote
 
  #76 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

Optimization of Double Stochastic

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.

Reply With Quote
 
  #77 (permalink)
Elite Member
Madison, WI
 
Futures Experience: Advanced
Platform: Sierra Charts, ALT
Favorite Futures: ES
 
aslan's Avatar
 
Posts: 614 since Jan 2010
Thanks: 342 given, 1,077 received


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)
Elite Member
Santa Maria
 
Futures Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker/Data: Mirus/Zen-Fire
Favorite Futures: ES
 
Posts: 295 since May 2010
Thanks: 101 given, 320 received


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.

https://futures.io/ninjatrader-programming/4416-fluxsmiths-indicators-2.html#post48849
https://futures.io/ninjatrader-programming/4416-fluxsmiths-indicators-2.html#post48850

Reply With Quote
 
  #79 (permalink)
Elite Member
Portland Oregon, United States
 
Futures Experience: Beginner
Platform: Ninjatrader®
Broker/Data: CQG, Kinetick
Favorite Futures: Gameplay Klownbine® Trading of Globex
 
Zondor's Avatar
 
Posts: 1,327 since Jul 2009
Thanks: 1,246 given, 2,635 received

The Blau TSI - Horrible Coding!

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.


Last edited by Zondor; April 1st, 2012 at 04:11 AM.
Reply With Quote
The following 2 users say Thank You to Zondor for this post:
 
  #80 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,177 since Oct 2009
Thanks: 228 given, 4,097 received


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
The following 2 users say Thank You to gomi for this post:

Reply



futures io > > > > > Anyone have any hints for optimizing C# code?

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hints, Tips & Gocthas NW27 MultiCharts 2 August 7th, 2011 04:11 PM
Can someone code this ? skyfly NinjaTrader Programming 8 April 25th, 2011 01:40 PM
Japan's Intervention Hints Fail to Stall Yen's Strength Quick Summary News and Current Events 0 September 8th, 2010 03:20 AM
Optimizing Range Bar Settings? daedalus Traders Hideout 3 February 1st, 2010 01:00 AM
Does anyone esle find Ninja problematic for optimizing strategies? rsi77 NinjaTrader 3 June 17th, 2009 09:32 PM


All times are GMT -4. The time now is 06:58 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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 2017-12-14 in 0.16 seconds with 40 queries on phoenix via your IP 54.226.227.175