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

  #81 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary

Putting Lipstick on A Pig ?


Zondor View Post
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.

The TSI is a NinjaTrader default indicator, itis not the worst indicator that I have seen. At least it calculates correctly.

I have tried to use the FirstTickOfBar() condition for many indicators, and it does not always improve performance. The problem is that I do not know what NinjaTrader does if I check for FirstTickOfBar ...

In this case the FirstTickOfBar condition would just save me a few multiplications, so I would not consider it worth using FirstTickOfBar. This does not invalidate the concept. For one of my MTF VWAPs, I was certainly able to improve performance over 1,000 times during news releases, by using both FirstTickOfBar and a recursive formula. It all depends what is in the bracket.

For the TSI I just would take out the divisions into OnStartUp(). This gives me a piglet without lipstick. The gain in performance was not measurable.


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

Attached Files
Register to download File Type: zip TSI_Piglet_No_Lipstick.zip (3.9 KB, 27 views)
Reply With Quote
The following 3 users say Thank You to Fat Tails for this post:
 
  #82 (permalink)
Membership Revoked
los angeles
 
Futures Experience: Intermediate
Platform: nt
Favorite Futures: cl
 
Sunil P's Avatar
 
Posts: 292 since Jan 2012
Thanks: 427 given, 175 received

Pig reminds me of my ex wife....biatch

A King Cobra is a more docile creature and trading CL is more predictable.

Reply With Quote
 
  #83 (permalink)
Elite Member
Berlin, Europe
 
Futures Experience: Advanced
Platform: NinjaTrader, MultiCharts
Broker/Data: Interactive Brokers
Favorite Futures: Keyboard
 
Fat Tails's Avatar
 
Posts: 9,651 since Mar 2010
Thanks: 4,226 given, 25,599 received
Forum Reputation: Legendary



Sunil P View Post
Pig reminds me of my ex wife....biatch

A King Cobra is a more docile creature and trading CL is more predictable.

C# does neither stand for Cheating on Your Spouse, Cobra or CL. It is just a coding language.

Reply With Quote
The following user says Thank You to Fat Tails for this post:
 
  #84 (permalink)
Membership Revoked
los angeles
 
Futures Experience: Intermediate
Platform: nt
Favorite Futures: cl
 
Sunil P's Avatar
 
Posts: 292 since Jan 2012
Thanks: 427 given, 175 received

Sorry Fats ...I got confused with another forum and its more colorful vernicular that C and CL reminded me of...

As you noticed,I usually just crack jokes....nothing of hard substance in my comments...usually.


Last edited by Sunil P; April 1st, 2012 at 02:59 PM.
Reply With Quote
 
  #85 (permalink)
Membership Revoked
los angeles
 
Futures Experience: Intermediate
Platform: nt
Favorite Futures: cl
 
Sunil P's Avatar
 
Posts: 292 since Jan 2012
Thanks: 427 given, 175 received

MIT OpenCourseWare | Electrical Engineering and Computer Science | 6.096 Introduction to C++, January IAP 2011 | Home


FYI

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

Blau TSI continued

During the lifetime of any bar, the output values of any DataSeries that have an index value other than zero do not change. Therefore the calculation of any algebraic expressions involving terms such as Close[1] only needs to be done OnFirstTickOfBar, NOT on every tick. There are about half a dozen of these expressions that can be isolated in Blau TSI. Some have arithmetic divisions in them, so not doing them on every tick is a big help since division is costly per Gomi.

I was surprised to see so much interest in this post... good!

@gomi, doesn't the calculation of 1/x entail division? Is multiplying by 1/x less costly than dividing by x?

FatTails, the piglet is so cute, what is his name? Does he have a Facebook® page?

Three things about FirstTickOfBar that we need to be aware of:
  • For historical data it is actually LAST Tick of Bar.
  • In a multiseries indicator you will get crazy results unless you are specific to a barsarray series For example If(BarsInPRogress==0 && FirstTickOfBar)
  • By the time FirstTickOfBar is true, the values of all the variables have ALREADY been set to the values appropriate to the new bar.


Last edited by Zondor; April 2nd, 2012 at 10:51 AM.
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #87 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,173 since Oct 2009
Thanks: 227 given, 4,089 received


Zondor View Post
@gomi, doesn't the calculation of 1/x entail division? Is multiplying by 1/x less costly than dividing by x.

Of course calculation of 1/x implies a division, that's why I mentioned "if you have lost of divisions by a rarely changing x", so you can only make the division once , and use the result afterwards.

Also remember that with NT , you're likely to see the improvement only on very heavy numerical computations...

And a last word, only try to outsmart the compiler when you know what you're doing. For instance if you're only dividing by constant numbers (available at compile time), the compiler will optimize the division.
example : optimization - What's the fastest way to divide an integer by 3? - Stack Overflow


Last edited by gomi; April 2nd, 2012 at 12:08 PM.
Reply With Quote
The following 2 users say Thank You to gomi for this post:
 
  #88 (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

Improving Ninjatrader Performance: The Big Picture

There are now two complementary approaches that, together, will give a big performance boost to Ninjatrader. And there is only one place on the web where you will find this information... Big Mike's. The two approaches are:

  1. Reducing resource usage of indicators

  2. Moving the historical chart and replay data from the System Disk to a faster or less busy device, ideally a RAM disk but alternately a non system SSD or HDD, as discussed in https://futures.io/ninjatrader/23998-speeding-up-ninjatrader-ram-drive.html#post274968


Regarding the first item:

What is being called "Optimizing" of code should not be confused with the process of optimizing a strategy by adjusting parameters. Maybe code improvement should be referred to as "Economizing".

I think that the CPU consumption of some indicators can easily be reduced by one or two orders of magnitude (90 to 99%) however, I have never tried to measure the change in performance. I think this could be done by inserting code into a control version and an economized version of an indicator that would measure, and print to the output window, things like the total time in ms to backfill historical data, and the total time per bar spent processing OnBarUpdate events.

Reply With Quote
The following 3 users say Thank You to Zondor for this post:
 
  #89 (permalink)
Trading Apprentice
Toledo, OH
 
Futures Experience: Advanced
Platform: NinjaTrader, proprietary API for TWS
Favorite Futures: NQ, YM, ES, FOREX
 
Posts: 41 since Nov 2012
Thanks: 16 given, 44 received

Output window is a great tool

Hello,
I agree with the previous post. There is nothing better than outputting/printing time to the output window before and after critical chunks of code to figure out the bottleneck. Pay attention to variables, array size for memory, switch statements instead of if/else where applicable and use of Ninja's multi threading. ( using OnMarketUpdate with OnBarUpdate to divvy up the functions as they will be called at different events but may accomplish the task faster together)

Thx

Reply With Quote
 
  #90 (permalink)
Elite Member
Cheltenham
 
Futures Experience: Advanced
Platform: InvestorRT, NinjaTrader
Favorite Futures: ES
 
Posts: 54 since Jan 2012
Thanks: 8 given, 100 received



eDanny View Post

private EMA emathingy;
emathingy = EMA(CCI(CCIPeriod),10);

In the example above, there is a EMA and a CCI indicator, but a reference is created only for the EMA.

Should there be a reference for the CCI too, such as in the example below?


private EMA emathingy;
private CCI cmithingy;

cmithingy = CCI(CCIPeriod);
emathingy = EMA(cmithingy,10);

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 01:29 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.18 seconds with 40 queries on phoenix via your IP 54.145.16.43