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,803 / 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?

  #41 (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

Wild Proliferation of Indicator Instances

"Yeah, I can't see the code you are posting, but just be aware that when you change the inputs you are actually creating an additional indicator that runs in parallel with the original one. So, that can easily get out of hand if you don't do some quantizing... like: instead of changing the SMA length each bar, only change it in length multiples of 5, or whatever."

Richard,

Is there a way to destroy the original one when I create the new one, so that only one instance will exist? Can I use Dispose() to do that?

Thanks to you we are making some great progress in this thread now. It's making a real difference.

Reply With Quote
 
  #42 (permalink)
Trading for Fun
Dallas TX/USA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: ES
 
Posts: 154 since Jun 2009
Thanks: 33 given, 281 received


eDanny View Post
Thanks Richard. I would be right back to using a DataSeries in that example so that is NOT the way to go.

I just want to make sure we're on the same page. Storing a reference to an existing DataSeries doesn't cost anything. Creating a new dataseries and filling it with values from another one is wasteful.

So, putting this in the init code:
 
Code
DataSeries macdavg; 
macdavg = MACD(12,26,9).Avg;
... costs nothing, and leaves you with access to the Dataseries that the MACD is filling. On the other hand:

 
Code
// Init Code
macdavg = new DataSeries(this);
...
// OnBarUpdate():
macdavg.Set(MACD(12,26,9).Avg[0]);
... stores copies of data that you already had access to, which is wasteful. In both cases, you end up with a DataSeries called macdavg that has the correct values in it, but the first version is practically free and the second one does a bunch of unnecessary work.

Reply With Quote
The following 4 users say Thank You to Richard for this post:
 
  #43 (permalink)
Trading for Fun
Dallas TX/USA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: ES
 
Posts: 154 since Jun 2009
Thanks: 33 given, 281 received



Zondor View Post
Is there a way to destroy the original one when I create the new one, so that only one instance will exist? Can I use Dispose() to do that?

I don't think so, because ninja is caching them and you don't know who else is looking at that same indicator reference. In the same way, you can't just change an indicator's inputs on the fly, because someone else may be depending on the object continuing to compute the 5 SMA rather than the 10, or whatever.

The three easiest workarounds I know of are:
  • Quantize so that you only ever create a few indicators to cover the input space and you don't have to worry about it.
  • Make an indicator that knows how to vary itself in the right way, rather than having the main indicator in control of adjusting the inputs (for bonus points, market it to people as an "adaptive indicator" for tons of cash to fund further development)
  • Suck the indicator code into a private function of the main indicator, so that you can call it with different inputs at will

Reply With Quote
The following user says Thank You to Richard for this post:
 
  #44 (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

Minimizing the use of MIN and MAX

Based on the suggestion by Richard in Post 38, I changed the DoubleStochasticsOptimized to check within the indicator, when a new bar starts, whether the [Period +1] value is equal to the minimum or maximum value for each of four different dataseries.

It is necessary to call the external MIN or MAX function ONLY when that is true.

A 30 tick, 30 days back chart of the YM with this indicator refreshes in less than one second.

(Printing the value of CurrentBar to the Output Window shows that this chart has 99,798 bars. ) That seems pretty good.....

Attached Files
Register to download File Type: cs DoubleStochasticsOptimized.cs (10.2 KB, 27 views)
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #45 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,214 received

In linux cli world, we can easily time stuff to find which method is most CPU efficient, just:

time <what you want to time>

It would be nice if a small block of code could be written to time these new optimized functions, so we can compare old vs. new and see what we are really accomplishing.

I'm all for writing efficient code and am just curious how much CPU time we're saving here. I think with .NET framework our only hope is to measure CPU time, measuring resource consumption like memory is not going to happen I don't think.

Mike

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #46 (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

Anecdotally, there is a definite difference in load time and workspace switching times since Zondor started his optimization project.

I am running 3 workspaces of 3 GOM Volume Ladders & 5 copies of BSV39 (both notoriously slow loaders). Load times went from 30 + seconds for the attached chart when hitting F5 to less than 8 seconds with 4 worksapces running. The fourth workspace has 12 GOM recorders -2 each of YM, CL, 6e flat and binary and 2 contract months each. Load time is less then 3 seconds if this is the only chart loaded in an empty workspace & that includes data.

R.I.P. Andy Zektzer (ZTR), 1960-2010.
Please visit this thread for more information.
Attached Thumbnails
Anyone have any hints for optimizing C# code?-ym-06-10-1024-volume-5_26_2010_2034.jpg   Anyone have any hints for optimizing C# code?-indys.png  
Reply With Quote
 
  #47 (permalink)
Trading for Fun
Dallas TX/USA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: ES
 
Posts: 154 since Jun 2009
Thanks: 33 given, 281 received


Zondor View Post
A 30 tick, 30 days back chart of the YM with this indicator refreshes in less than one second.

I had in mind more of a FastMAX and FastMIN indicator that you can use as replacements for the original MAX and MIN... so other indicators wouldn't need to know the difference. Like the attached.

I can run the new 89-max and 89-min on a chart with 2.8 million bars in 6 seconds, versus more like 19 seconds with the built-in max and min. It definitely makes a difference to avoid redundant computations.

Attached Files
Register to download File Type: cs Z20100527FastMAX.cs (7.1 KB, 55 views)
Register to download File Type: cs Z20100527FastMIN.cs (7.5 KB, 48 views)
Reply With Quote
The following 5 users say Thank You to Richard for this post:
 
  #48 (permalink)
Trading for Fun
Dallas TX/USA
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: AMP/CQG
Favorite Futures: ES
 
Posts: 154 since Jun 2009
Thanks: 33 given, 281 received

While we're on the topic of optimization, DoubleStochasticsOptimized has a line like this in it:

 
Code
			p2.Set(pEMA[0]);
Whenever you see a line like this, it is a sign that you probably don't need p2 at all. Just use pEMA.Value instead. Also, by using fastMAX and fastMIN you can put those into OnStartUp() and avoid the cache lookup.

Reply With Quote
The following user says Thank You to Richard for this post:
 
  #49 (permalink)
Elite Member
san ramon
 
Futures Experience: Beginner
Platform: ninja
Broker/Data: zen
Favorite Futures: es, 6e
 
Posts: 136 since Oct 2009
Thanks: 98 given, 73 received

I propose a new platform by Gomi and Richard ........ "Be Rich GoRich" .....

Reply With Quote
The following user says Thank You to zikonc for this post:
 
  #50 (permalink)
Just starting out...
London
 
Futures Experience: Advanced
Platform: Prop algos
Broker/Data: Rithmic
Favorite Futures: Futures
 
Posts: 16 since Mar 2010
Thanks: 0 given, 13 received



Big Mike View Post
It would be nice if a small block of code could be written to time these new optimized functions, so we can compare old vs. new and see what we are really accomplishing.

I'm all for writing efficient code and am just curious how much CPU time we're saving here. I think with .NET framework our only hope is to measure CPU time, measuring resource consumption like memory is not going to happen I don't think.

Try these puppies...

CPU profiling: EQATEC Profiler &mdash; EQATEC

Memory profiling: Download details: CLR Profiler for the .NET Framework 2.0

No need to part with any cash money.

Reply With Quote
The following user says Thank You to ScoobyStoo 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)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

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 01:54 AM.

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-11 in 0.13 seconds with 40 queries on phoenix via your IP 54.226.34.209