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

  #21 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,173 since Oct 2009
Thanks: 227 given, 4,089 received

I'm answering my own question : as a matter of fact you can now develop non-blurry WPF apps with .NET version 4.0
cf Scott Hanselman - WPF and Text Blurriness, now with complete Clarity

This version was released on april 12th 2010, so let's say it's been 11 days that's it's possible to develop a visualization app with WPF.. ;-)

Reply With Quote
The following 2 users say Thank You to gomi for this post:
 
  #22 (permalink)
Membership Revoked
Szczecin
 
Futures Experience: Intermediate
Platform: Ninja, writing own now
 
Posts: 212 since Mar 2010
Thanks: 47 given, 102 received

Small font rendering was significantly improoved with 4.0 - you can not tell draw operations to align with physical pixels (good for small things) and a lot was done for making fonts more readable. I assume it helped that they made VIsual Studio in WPF now, so a lot of the problems start appearing in their own applications and THUS GET FIXED

Reply With Quote
 
  #23 (permalink)
Membership Revoked
British Columbia
 
Futures Experience: Advanced
Platform: NINJA
Broker/Data: ZEN
Favorite Futures: Crude
 
Posts: 1,091 since May 2010
Thanks: 192 given, 484 received


Hey Mike,

I was wondering if you would be interested in starting a thread on PC tweaking for traders. I want to learn this stuff and run my PC like a car freak mechanic would run his muscle car..

I'd also like to start on for learning how to tweak NT7, maintain it, and how best to learn C# and what other things you need to know to tweak indicators. I noticed one book on C# in the books thread. Is that a good place to start do you think?

Reply With Quote
 
  #24 (permalink)
 Vendor: www.wmtrading.org 
NSW Australia
 
Futures Experience: Advanced
Platform: MT4/MT5/ Multicharts/Ninja Trader
Broker/Data: gain
Favorite Futures: forex
 
waza1960's Avatar
 
Posts: 33 since May 2010
Thanks: 38 given, 38 received

Hoping somebody can help me here.I'm running N6.5 using a VPS (windows server2003 750mb Ram single core.I run a simulation with 12 strategies for a month went perfectly.
I've started trading live 3 days ago and I suddenly get these messages saying that ninja was unable to submit an order due to not enough free threads in the thread Pool.
I contacted Ninja support forum and they say its a VPS problem I contact the VPS people and they say that its not their problem. I can't find any relevant info on the net.
I was wondering if the RAM being less than recommended was an issue (I don't use the VPS for any thing other than simulation and live automated trading).Maybe I need to upgrade to windows server2008 or multiple cores. opinion or advise welcome

Reply With Quote
 
  #25 (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,218 received


waza1960 View Post
Hoping somebody can help me here.I'm running N6.5 using a VPS (windows server2003 750mb Ram single core.I run a simulation with 12 strategies for a month went perfectly.
I've started trading live 3 days ago and I suddenly get these messages saying that ninja was unable to submit an order due to not enough free threads in the thread Pool.
I contacted Ninja support forum and they say its a VPS problem I contact the VPS people and they say that its not their problem. I can't find any relevant info on the net.
I was wondering if the RAM being less than recommended was an issue (I don't use the VPS for any thing other than simulation and live automated trading).Maybe I need to upgrade to windows server2008 or multiple cores. opinion or advise welcome

750mb ram is not enough to run NinjaTrader. I assume your home machine has 2GB or more, hopefully 4GB or more, just run the strategy live from home for a day and see if you have the same problems.

Server 2008 isn't going to do anything except add more services and slow things down. Your best bet is XP or Windows Seven, and 2GB of ram if you are using NT 6.5.

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
 
  #26 (permalink)
Elite Member
London
 
Futures Experience: None
Platform: MC & Ninja mainly
 
Posts: 130 since Jan 2010
Thanks: 3 given, 47 received

Try to use online algorithms wherever possible. Online algorithm - Wikipedia, the free encyclopedia
For example put any of the VWAP algorithms on a 1 tick chart of the ES to see what I mean!

Essentially you want to avoid looping through the data as much as possible. A good example is a simple moving average. The way most new to programming would tackle that is some sort of loop to iterate over the last N bars and sum the total. Really you should

add close[0]/period
subtract close[period]/period

That is about the simplest type of optimisation but wherever you see a loop you want to try and look at eliminating it if possible. There are always places where you are iterating through ticks or bars or something or other.

I know very little about .NET but have started to try and get up to speed on it. Having said that I hear one area to be wary of is garbage collection (as with any managed framework), it is widely written about.

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


waza1960 View Post
I've started trading live 3 days ago and I suddenly get these messages saying that ninja was unable to submit an order due to not enough free threads in the thread Pool.

This is called thread starvation. The .NET runtime allocates one thread pool per process (i.e. NT). In .NET2.0 the thread pool has a default size of 25 worker threads per available processor. In .NET3.5 Microsoft increased this to 250 worker threads. However, NT6.5 runs on .NET2.0 so you are only getting 25 worker threads.

Just found your post on the NT support forum. From the screenshot I can see you are getting an InvalidOperationException when NT invokes HttpWebRequest.BeginGetRequestStream. This is a common problem which NT should be aware of.

See this link...

Contention, poor performance, and deadlocks when you make Web service requests from ASP.NET applications

Try adding the following line of code to the initialisation method of your NT strategy.

 
Code
System.Threading.ThreadPool.SetMaxThreads(250, 1000);
See if that helps. It'll bump up the number of threads in the pool.


waza1960 View Post
I contacted Ninja support forum and they say its a VPS problem I contact the VPS people and they say that its not their problem.

This is a software issue, not a VPS issue. Send that link to NT and tell them to pull their finger out and look at their code rather than being so quick to point their finger at the VPS. They should be providing support for their product, not me. I suspect they are making numerous HttpWebRequest calls without understanding the ramifications for the thread pool. On a powerful machine you won't notice a problem because the worker threads will be freed up quickly but on a less powerful machine with limited CPU resources (such as your VPS) you've got a problem.


waza1960 View Post
I was wondering if the RAM being less than recommended was an issue (I don't use the VPS for any thing other than simulation and live automated trading).

This problem is completely unconnected to the RAM. But yes, you need a couple of Gig really to run NT comfortably. It's a memory hungry beast.


waza1960 View Post
Maybe I need to upgrade to windows server2008 or multiple cores. opinion or advise welcome

Stick with Win2003. There's no point in you upgrading to Win2008. Any increased CPU resources (such as additional cores) will definitely help. It sounds like you have a fairly low powered VPS instance and that's going to mean you don't get much CPU time allocated to you. Either get yourself a more powerful VPS or ditch the VPS entirely and run NT on a dedicated box instead (my preference).

Reply With Quote
The following 2 users say Thank You to ScoobyStoo for this post:
 
  #28 (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

Calling Ninjascript Indicators Efficiently

RWT-004 :: Move the Markets


Very interesting post at MoveTheMarkets. The way we usually do things is terribly inefficient and there is a better way:

"In all of the coding tutorials and examples I've seen, Ninjatrader indicators are used in-line. So, if you want to know when the SMA is going up, you'd check:
SMA(Close, 5)[0] > SMA(Close, 5)[1]
I find this practice repulsive for two reasons: redundancy and inefficiency. This paper chronicles the path I took to fifinding a better way. If you just want to know what the better way is, skip to the 'Solution' section at the end......"

Reply With Quote
 
  #29 (permalink)
Elite Member
London
 
Futures Experience: None
Platform: MC & Ninja mainly
 
Posts: 130 since Jan 2010
Thanks: 3 given, 47 received

"The problem is in the caching scheme that Ninjatrader uses for momoization. First off, it's a simple linear search!"

Hmm that is precisely the kind of thing I was eluding too above. You really don't want to be looping through 'stuff'. Loops are bad. Of course if ninja is doing it internally you have problems (as Richard discovered)

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

Calling Indicators Efficiently - This is VERY IMPORTANT


Anyone writing Ninjascript code should look at that post at MoveTheMarkets, and implement that idea in their code.

A good test case is the BigMike CollectiveMA. It makes six calls to external MA's.

I already changed it as Richard suggested, and I can easily see that it loads much faster now.

These changes are very easy to make, only taking a few minutes. When you think about it, doing that in an indicator that uses six calls to external MA's will cut the resources used by the indicator to a small fraction of the original demands.

Reply With Quote

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 11:01 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-11 in 0.14 seconds with 40 queries on phoenix via your IP 54.145.16.43