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

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

answering previous question


Quoting 
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);

Yes, as long as the value of CCIPeriod does not change within the indicator.

Once in a while, as in "Adaptive" indicators, the parameters of external classes vary under programmatic control.


Last edited by Zondor; November 29th, 2012 at 05:07 PM.
Reply With Quote
 
  #92 (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 Aggressive Optimization

The LinReg indicator does not have much of a performance impact but this example shows how it can be made more efficient.
  • Calls to the external SUM class eliminated. SUM algorithm moved into this indicator. Beats using a reusable instance of the external SUM class.
  • Variables that do not change intrabar are calculated only on FirstTickOfBar.
  • OnBarUpdate does not process redundant intrabar ticks.
  • Single precision "Float" variables reduce amount of arithmetic and memory load since a Float has half the bytes of a Double.

If you want to use this, rename the file to @LinReg and REPLACE the existing file that has that name.

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Attached Files
Register to download File Type: cs LinReg.cs (6.8 KB, 40 views)

Last edited by Zondor; December 11th, 2012 at 05:13 PM.
Reply With Quote
The following 3 users say Thank You to Zondor for this post:
 
  #93 (permalink)
Elite Member
Manchester, NH
 
Futures Experience: Beginner
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: Stocks
 
Posts: 902 since Jul 2012
Thanks: 603 given, 1,785 received


@Zondor

You actually lose performance by downcasting those doubles. C# double addition takes 0.11 ns more than float addition on a 2 GHz machine, all else is the same. So downcasting is more expensive for your algorithm. I would only do it if the memory bandwidth was comparable to the L2 cache.

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

using floats instead of doubles

Thanks @artemiso, I was wondering about that. The float downcasting is a sledgehammer approach.

I was brought up in the days of slide rules, so am very aware that doing arithmetic with excessive non signficant precision is very wasteful. But I am not sure that there is any good way to curtail it. Math.Round, Trunc, and string formatting don't sound like good options either.

Noticed that lots of people have looked at this post. You are probably admiring my necktie and wondering where you can get your own.

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett

Last edited by Zondor; December 11th, 2012 at 05:07 PM.
Reply With Quote
The following 2 users say Thank You to Zondor for this post:
 
  #95 (permalink)
Elite Member
Manchester, NH
 
Futures Experience: Beginner
Platform: thinkorswim
Broker/Data: TD Ameritrade
Favorite Futures: Stocks
 
Posts: 902 since Jul 2012
Thanks: 603 given, 1,785 received


Zondor View Post
Thanks @artemiso, I was wondering about that.

Doing arithmetic with excessive non signficant precision is very wasteful, but I am not sure that there is any good way to curtail it. Math.Round, Trunc, and string formatting don't sound like good options either.

You're welcome. Unfortunately, modern processors are so fast that the primitives nearly all take 1 clock cycle. The extra precision is indeed wasteful, but it's here to stay.

Reply With Quote
The following user says Thank You to artemiso for this post:
 
  #96 (permalink)
Elite Member
Lubbock TX
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: Stage 5 Trading
Favorite Futures: CL
 
MWinfrey's Avatar
 
Posts: 1,879 since Jul 2009
Thanks: 1,449 given, 3,306 received


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

@Zondor, @Richard

That movethemarkets link does not work any longer. Any ideas?

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

Move The Markets Moved On

@Richard closed it down to pursue other interests, but hopefully is still around on futures.io (formerly BMT).

Too bad, there was some great stuff posted there.

"If we don't loosen up some money, this sucker is going down." -GW Bush, 2008
“Lack of proof that something is true does not prove that it is not true - when you want to believe.” -Humpty Dumpty, 2014
“The greatest shortcoming of the human race is our inability to understand the exponential function.”
Prof. Albert Bartlett
Reply With Quote
The following user says Thank You to Zondor for this post:
 
  #98 (permalink)
Elite Member
Paris
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 1,177 since Oct 2009
Thanks: 228 given, 4,097 received


MWinfrey View Post
@Zondor, @Richard

That movethemarkets link does not work any longer. Any ideas?

RWT-004 :: Move the Markets ?

Found it on NT support site
Best practice for programming efficient indicators for the NT Strategy Analyzer? - NinjaTrader Support Forum

Reply With Quote
The following 7 users say Thank You to gomi for this post:
 
  #99 (permalink)
Elite Member
Orange County, CA / United States
 
Futures Experience: Advanced
Platform: NinjaTrader, Excel/VBA
Broker/Data: IB / Kinetick / eSignal
Favorite Futures: Equities
 
Posts: 17 since Nov 2012
Thanks: 11 given, 15 received

I'm learning more about this topic and found this thread really helpful. Thank you!

Here is the movethemarkets PDF "Calling Upon Indicators Efficiently in NinjaScript" (attached)

Also, found this thread which has some more good info on this topic:

Best practice for programming efficient indicators for the NT Strategy Analyzer
Best practice for programming efficient indicators for the NT Strategy Analyzer? - NinjaTrader Support Forum

Attached Thumbnails
Anyone have any hints for optimizing C# code?-calling-upon-indicators-efficiently-ninjascript.pdf  
Reply With Quote
The following 2 users say Thank You to ntvola for this post:
 
  #100 (permalink)
Elite Member
Calgary AB
 
Futures Experience: Intermediate
Platform: AmiBroker, IB
Broker/Data: Interactive Brokers
Favorite Futures: Stocks
 
Posts: 10 since Mar 2013
Thanks: 5 given, 2 received


How would you go about this "economization" of indicators if you are using a multi-instrument strategy?

ie, if you declared

 
Code
class MyIndicator : Indicator {
private SMA sma1;
private SMA sma2;
...
protected void override OnStartup() {
sma1 = SMA(Close,5);
sma2 = SMA(Close, 13);
...
}
How could you then call sma1 or sma2 for a BarsArray[index] item?

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)

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 03:45 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-17 in 0.14 seconds with 40 queries on phoenix via your IP 107.20.115.174