Common code re-use - NinjaTrader Programming | futures io social day trading
futures io futures trading


Common code re-use
Updated: Views / Replies:3,474 / 12
Created: by LostTrader Attachments:0

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
 
Thread Tools Search this Thread
 

Common code re-use

  #1 (permalink)
Elite Member
Tucson, AZ
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL, TF
 
LostTrader's Avatar
 
Posts: 74 since Sep 2009
Thanks: 21 given, 62 received

Common code re-use

Does anyone have a preferred method of re-using common code (or code snippets) in NinjaScript?

Back when I used to write real code, I could embed a file which the compiler would pull in and place inline before compiling, so I could re-use common sections without replicating the same lines in multiple places. I would love to be able to do that in NinjaTrader.

I have written separate namespaces, with custom classes, and saved/compiled the script in the Indicator directory. Then added "Using name;" with the others at the top of the Indicator script that used the class. However, since the namespace isn't built off the Indicator code, I haven't figured out how to use Print() or any of the NinjaScript functions.

Likewise, I can write a static class that can be used by any other without forcing an instantiation, but it has similar limitations.

What solutions have others used?

Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

How to re-use the same common code file in NinjaScripts?

 
  #3 (permalink)
Elite Member
Santa Maria
 
Futures Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker/Data: Mirus/Zen-Fire
Favorite Futures: ES
 
Posts: 295 since May 2010
Thanks: 101 given, 320 received


I ran into the problem yesterday of not being able to use Print, I'm sure there's some global object for the output window we need to get our hands on, but I don't know what it is.
My solution was intrusive but if I really need to communicate an error condition, I found that calling System.Windows.Forms.MessageBox.Show works.

Reply With Quote
 
  #4 (permalink)
Elite Member
San Francisco Bay Area
 
Futures Experience: Intermediate
Platform: NT,TOS,IB
Favorite Futures: ES,CL,TF
 
Posts: 278 since Jun 2010
Thanks: 154 given, 267 received

In your custom code accept the NT Strategy/Indicator object as a parameter to the constructors. You can then call the NT functions from your code via the handle you have to the NT data-structures.

 
Code
 
using NinjaTrader.Data;
using NinjaTrader.Cbi;
using NinjaTrader.Strategy;
...
class CustomCode{
...
StrategyBase parentStrat;
...
public CustomCode(StrategyBase pStat) { // constructor
                    parentStrat = pStat;
                    pStat.TraceOrders = true;
            }

// Now use parentStrat.Method in your code

Reply With Quote
 
  #5 (permalink)
Elite Member
Tucson, AZ
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL, TF
 
LostTrader's Avatar
 
Posts: 74 since Sep 2009
Thanks: 21 given, 62 received

Thanks for the suggestions, keep 'em coming!

I have wondering about the resource consumption by instantiating (calling a constructor) a class simply to re-use common code. NT is not the most efficient compiler in the world and I wonder about excess memory consumption and performance impacts. Up til now, the only methods I moved to a separate class were those which could be static, so no instantiation (construction) is required to call them.

I know one person got around not having the NT Draw routines by overriding the chart plot routines and creating his own.

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

You can profile NinjaScript C# code:

https://futures.io/help-tutorials-how-tos/4508-how-profile-ninjatrader-code-visual-studio-2010-a.html

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
 
  #7 (permalink)
Elite Member
Tucson, AZ
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL, TF
 
LostTrader's Avatar
 
Posts: 74 since Sep 2009
Thanks: 21 given, 62 received

Thanks Mike. I was actually looking at some Visual Studio links earlier -- it would be nice but I don't have Visual Studio and haven't quite figured out how much it costs, which version do I need, etc. One day I plan to get there.

So I started this thread hoping to encourage folks to share techniques that work with just NT. :-) For poor folk like me!

Reply With Quote
 
  #8 (permalink)
Elite Member
Santa Maria
 
Futures Experience: Advanced
Platform: NinjaTrader, ThinkOrSwim
Broker/Data: Mirus/Zen-Fire
Favorite Futures: ES
 
Posts: 295 since May 2010
Thanks: 101 given, 320 received

I don't know if it includes profiling or not, but you might be interested in the free version:
Microsoft Express Home - Visual Studio Express and SQL Server Express are free tools

Reply With Quote
 
  #9 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

VS 2010 Pro has some of that functionality and costs between $0-$500 depending on your use. I'm on the road now but that will be the subject of the next update in my "NinjaTrader and VS2010 for Dummies" thread when I'm back.

Basically you can create and edit your own Code Snippets for custom methods, etc which saves typing. The IDE also knows your file-specific variables, etc and can auto-fill them for you as you type.

Reply With Quote
 
  #10 (permalink)
Elite Member
Tucson, AZ
 
Futures Experience: Intermediate
Platform: Ninjatrader
Broker/Data: Mirus/Zen-Fire
Favorite Futures: CL, TF
 
LostTrader's Avatar
 
Posts: 74 since Sep 2009
Thanks: 21 given, 62 received


OK, I separated out the Visual Studio discussion to a separate thread because I do not want it to stop, but I do want to keep this thread on topic. So please bear with me.

If anyone has examples of C# common code re-use that they would liketo share, or more techniques that can be implemented in a NinjaScript cs file, please chime in!

I'll see if I can dig some out. I know that they are not "officially supported" so use at your own risk. But it is a great way to learn.

Reply With Quote

Reply



futures io > > > > > Common code re-use

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
Protecting code sam028 NinjaTrader Programming 30 April 21st, 2016 01:01 PM
Help with paintbar code. bfreefalling NinjaTrader Programming 2 April 28th, 2011 10:54 AM
Can someone code this ? skyfly NinjaTrader Programming 8 April 25th, 2011 01:40 PM
Obama’s Twist of BP’s Arm Stirs Common Tactic Debate Quick Summary News and Current Events 2 June 18th, 2010 10:39 AM
Having some issues with this code. Please help. kaywai NinjaTrader Programming 3 March 4th, 2010 11:33 AM


All times are GMT -4. The time now is 10:30 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-10 in 0.11 seconds with 19 queries on phoenix via your IP 54.221.73.186