NexusFi: Find Your Edge


Home Menu

 





Anyone have any hints for optimizing C# code?


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Zondor with 20 posts (21 thanks)
    2. looks_two ZTR with 13 posts (0 thanks)
    3. looks_3 Richard with 11 posts (20 thanks)
    4. looks_4 Fat Tails with 7 posts (18 thanks)
      Best Posters
    1. looks_one Fat Tails with 2.6 thanks per post
    2. looks_two gomi with 2.1 thanks per post
    3. looks_3 Richard with 1.8 thanks per post
    4. looks_4 Zondor with 1.1 thanks per post
    1. trending_up 48,625 views
    2. thumb_up 108 thanks given
    3. group 39 followers
    1. forum 111 posts
    2. attach_file 13 attachments




 
Search this Thread

Anyone have any hints for optimizing C# code?

  #61 (permalink)
Richard
Dallas TX/USA
 
Posts: 153 since Jun 2009
Thanks Given: 33
Thanks Received: 284


MXASJ View Post
Is there an example of how this code could be optimized? I'm still not getting what types of calculations should be taken out of OnBarUpdate... or am I totally missing something? Thanks for the enlightenment.

There's no way to meaningfully speed up that indicator. It basically does the minimum that it needs to do. Make sure the market analyzer only uses the minimum number of bars back that you need. And if you only need the realtime numbers, you could try adding:

 
Code
if(!Historical) { ... }
... around the whole thing, to avoid doing any calculation at all, except for the most recent bar. (you'd do this in a copy of ROC, and not ROC itself!)

Since ROC does so little, I don't know how much that would help, but it's the first thing I'd try.

Reply With Quote
Thanked by:

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
NexusFi Journal Challenge - May 2024
Feedback and Announcements
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
 
  #62 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425

Richard, what is the difference here?

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

and

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

Which is better here?

private MACD macdThingamajig;
macdThingamajig = MACD(12,26,9);

then use: macdThingamajig.Avg[0]

or

DataSeries macdThingamajig;
macdThingamajig = MACD(12,26,9).Avg;

then use: macdThingamajig[0]

Reply With Quote
  #63 (permalink)
Richard
Dallas TX/USA
 
Posts: 153 since Jun 2009
Thanks Given: 33
Thanks Received: 284



eDanny View Post
Richard, what is the difference here?

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

and

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

It's the same thing, except in the second example you can hold a reference to any indicator, versus just the EMA. The main difference you'll see in practice is when indicators define properties for their plots. So, for instance, MACD has the "Avg" property, which gets you access to the dataseries for that particular plot. If you have "Indicator macd", then the best you can do is look up macd.Values[1]... because "Indicator" does not have a property named "Avg."

Performance-wise, it's a wash, though. It's the same objects. Just a matter of what you need access to through the variables you use.



eDanny View Post
private MACD macdThingamajig;
macdThingamajig = MACD(12,26,9);

then use: macdThingamajig.Avg[0]

or

DataSeries macdThingamajig;
macdThingamajig = MACD(12,26,9).Avg;

then use: macdThingamajig[0]

Again, it's all the same objects doing the same computations... the only difference is what you can access through the variables you are holding. In this case, you are storing off a reference to a particular dataseries in the MACD. So, from that point forward, you have direct access to it, but not to the MACD. You didn't store off a reference to the MACD.

But, if all you were needing was the 'Avg' data, then it's all the same, and in fact a few cycles faster. Nothing you'd notice, so I tend to store references to the indicators for maximum flexibility.

Reply With Quote
Thanked by:
  #64 (permalink)
 
eDanny's Avatar
 eDanny 
East Rochester, NY
 
Experience: Intermediate
Platform: NT
Posts: 329 since Jul 2009
Thanks Given: 18
Thanks Received: 425

Thanks Richard, those answers are exactly what I was thinking but wanted confirmation.

Dan

Reply With Quote
  #65 (permalink)
 
SteveM's Avatar
 SteveM 
Toronto, Canada
 
Experience: Beginner
Platform: Ninja Trader
Broker: Amp Futures/ Zen-Fire
Trading: Still not sure what is my favourite instrument.
Posts: 155 since Jul 2009
Thanks Given: 464
Thanks Received: 112

I am unable to download the indicator Double Stochastic Optimized, LATEST VERSION V1.4 on NT6.5. I am getting a message: Import failed. Ninja Trader could not decompress the Ninja Script Archive File: Version required to extract this entry not supported (45).

Can some one help me with this. Please.

Thanks

Steve

Thanks
Steve
Be like a JAGUAR. Crouching, perfectly still, waiting for the set up to come to you, then pouncing without hesitation or thought. You only need one to feed the family
Visit my NexusFi Trade Journal Reply With Quote
  #66 (permalink)
 
ZTR's Avatar
 ZTR 
 
Experience: Advanced
Platform: NinjaTrader7
Broker: Mirus RCG/Zen-Fire
Trading: CL & 6e, looking at ES, ZB and AU again.
Posts: 2,096 since Nov 2009
Thanks Given: 1,099
Thanks Received: 1,393


SteveM View Post
I am unable to download the indicator Double Stochastic Optimized, LATEST VERSION V1.4 on NT6.5. I am getting a message: Import failed. Ninja Trader could not decompress the Ninja Script Archive File: Version required to extract this entry not supported (45).

Can some one help me with this. Please.

Thanks

Steve

Try deleting the info.xml file from the installation folder and paste in the .cs file into an empty shell. I have posted about this if you have questions.

But you may have to upgrade to NT7 to get the really good stuff on the forum, Zondor and I no longer even have 6.5 on our computers.

R.I.P. Andy Zektzer (ZTR), 1960-2010.
Please visit this thread for more information.
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #67 (permalink)
 kees 
Nederland
 
Experience: Intermediate
Platform: NinjaTrader
Broker: Zen-Fire
Posts: 17 since Jun 2009
Thanks Given: 42
Thanks Received: 4

Can someone please make this indicator working for NT 6.5
Thanks

Reply With Quote
  #68 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,460 since Jun 2009
Thanks Given: 33,234
Thanks Received: 101,655


kees View Post
Can someone please make this indicator working for NT 6.5
Thanks

I think you are in the wrong place. You should post requests for indicators in this thread:



Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #69 (permalink)
 
ZTR's Avatar
 ZTR 
 
Experience: Advanced
Platform: NinjaTrader7
Broker: Mirus RCG/Zen-Fire
Trading: CL & 6e, looking at ES, ZB and AU again.
Posts: 2,096 since Nov 2009
Thanks Given: 1,099
Thanks Received: 1,393

Great ideas to optimize NT indy's From Richad Todd: [COLOR=#0066cc]http://www.movethemarkets.com/downloads/rwt/rwt004/[/COLOR]

I truely believe this person runderstands computer processing, especially when applied to NinjaTrader 7 & hope this is not considered an advertisement for this site as I have no idea if he is selling anything directly on this page.

R.I.P. Andy Zektzer (ZTR), 1960-2010.
Please visit this thread for more information.
Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #70 (permalink)
 aviat72 
San Francisco Bay Area
 
Experience: Intermediate
Platform: NT,TOS,IB
Trading: ES,CL,TF
Posts: 281 since Jun 2010
Thanks Given: 161
Thanks Received: 273


I originally wrote code for solving NP-type problems and performance was the one benchmark we were measured on. When I originally started writing my trading system, I was surprised to see that most commercial libraries do not use data-persistence and loop through the entire data-series. To me that was like driving forward while looking backwards.

It took me some time to realize that most of the world, including most programmers, are not measured on performance and are focussed on getting the job done quickly instead of performance. However when you start running this kind of code on tick data, you very quickly will start maxing out.

This brings me to the question of NT. Though NT7 uses multi-threading the main charting loop is still a single thread. This means that your super-duper quad-core CPU will basically be no better than a single/dual core CPU with the same core and memory system (assuming you are not doing anything else). Back-testing and optimization does use the multiple threads and will run faster on more cores.

I have often faced performance problems with NT with the CPU maxing out at 25% (One core of a quad core). I now try to use CalculateOnBarClose or write my own sampled version for larger time-frame bars i.e. the indicator will update 10 times, during the bar but not on every tick. However this is still inefficient since the OnBarUpdate() method is called on every tick and the check for sampling does take some time.

I am attaching the basic sampled indicator from which other indicators can derive from. It is very much like the gomi indicators. There is also an example which converts the TSI to the SampledTSI.

Attached Files
Elite Membership required to download: AviatSampledIndicator.cs
Elite Membership required to download: BlauTSISampled.cs
Visit my NexusFi Trade Journal Reply With Quote




Last Updated on December 24, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts