NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 06-04-2012, 08:27 AM   #1
ij001
Senior Member
 
Join Date: Apr 2010
Posts: 125
Thanks: 18
Thanked 3 times in 3 posts
Default Object Oriented Programming in NT

I recently opened my dusty C# for Dummies book and have learned that the programming I’ve done in NT is more “procedural” in nature than “object oriented”.

(Sigh) This bothers me a bit because I thought since I have methods I have objects. That doesn’t seem to be the case…
Anyway I’m going to change my code from flow chart to more OOP. I need the flexibility of being able to add new things as they come up. Also, being able to call objects as opposed to having multiple variables that do the same thing will serve me well.

Anyway, I was looking for confirmation, in my indicators code I was going to create different classes for the objects I have and go from there. I quickly created a blank class and it compiled without any issues.
Are people here with larger programs doing that?

The indicator itself obviously will always be the main class (public class MyClass: Indicator) with OnBarUpdate being where the action is. But if we can create methods anywhere we can do the same with classes and then create objects from them?

Thx
Irvin

https://github.com/sempf/CSharpForDummies
ij001 is offline  
Reply With Quote
Old 06-04-2012, 08:33 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Irvin,

NinjaTrader is based on the .NET framework which uses C#. You can create your own classes for use with indicators, etc. and there are many developers doing so.

NinjaScript is setup as sort of a more functional / procedural programming language just for ease of use by inexperienced programmers but OOP should be supported as outlined in the .NET framework. You just need to keep track of the namespaces, etc. engineering part of NinjaTrader when you program your own classes for use in particular indicators or strategies.

Please let me know if I may assist further.
Last edited by NinjaTrader_AdamP; 06-04-2012 at 11:23 AM.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-04-2012, 08:53 AM   #3
ij001
Senior Member
 
Join Date: Apr 2010
Posts: 125
Thanks: 18
Thanked 3 times in 3 posts
Default

Hi Ryan

Thanks for your reply.

All my methods are in UserDefinedMethods so I will create my objects there.

Btw, where is the code for NinjaTrader.Data?
That is a namespace?
That is where say, the code for DataSeries would be?

Thx
Irvin
ij001 is offline  
Reply With Quote
Old 06-04-2012, 09:05 AM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Irvin,

That would be a global class that would be accessible in both strategy and indicator namespaces.

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-04-2012, 09:16 AM   #5
ij001
Senior Member
 
Join Date: Apr 2010
Posts: 125
Thanks: 18
Thanked 3 times in 3 posts
Default

Quote:
Originally Posted by NinjaTrader_AdamP View Post
Irvin,

That would be a global class that would be accessible in both strategy and indicator namespaces.

Please let me know if I may assist further.
What would be global?

I thought you could only have code in UserDefinedMethods for indicators and then use the UserDefinedMethods for strategies?

Currently I copy my code from indicators UserDefined to strategies userdefined...
ij001 is offline  
Reply With Quote
Old 06-04-2012, 09:42 AM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

Irvin,

Apologies, I misunderstood. The NinjaTrader.Data is accessible in both namespaces, however isn't exposed for editing/viewing.

The My Documents / NinjaTrader 7 / bin / custom / indicator and strategy directories each have their own UserDefinedMethods.cs you can use for each respectively.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-04-2012, 04:49 PM   #7
koganam
Senior Member
 
Join Date: Feb 2008
Location: Durham, North Carolina, USA
Posts: 3,218
Thanks: 24
Thanked 1,231 times in 1,002 posts
Send a message via Skype™ to koganam
Default

Quote:
Originally Posted by ij001 View Post
I recently opened my dusty C# for Dummies book and have learned that the programming I’ve done in NT is more “procedural” in nature than “object oriented”.

(Sigh) This bothers me a bit because I thought since I have methods I have objects. That doesn’t seem to be the case…
Anyway I’m going to change my code from flow chart to more OOP. I need the flexibility of being able to add new things as they come up. Also, being able to call objects as opposed to having multiple variables that do the same thing will serve me well.

Anyway, I was looking for confirmation, in my indicators code I was going to create different classes for the objects I have and go from there. I quickly created a blank class and it compiled without any issues.
Are people here with larger programs doing that?

The indicator itself obviously will always be the main class (public class MyClass: Indicator) with OnBarUpdate being where the action is. But if we can create methods anywhere we can do the same with classes and then create objects from them?

Thx
Irvin

https://github.com/sempf/CSharpForDummies
Not quite. NT indicators and strategies are composed as classes. The code inside a class is ultimately always precedural. Even if you nest classes, your innermost class will have to be procedural. After all, all methods, even if they use class constructs, are themselves procedural.

NT seems to be using the now generally accepted standard convention of one class per file, thereby turning each file itself in effect into an object. The code in the object, consisting of methods, variables and other objects will itself be procedural.

OOP refers to how the data structures are closely entwined with the code for manipulating said data. OOP is not a reference to a coding style totally devoid of procedural elements. Indeed, it is actually impossible to write such code, because the internal methods of the classes must necessarily be procedural.

Just my $0.02.
Last edited by koganam; 06-05-2012 at 10:34 AM. Reason: Corrected spelling
koganam is offline  
Reply With Quote
The following user says thank you to koganam for this post:
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Best practice for programming efficient indicators for the NT Strategy Analyzer? poseidon_sthlm Indicator Development 12 01-24-2013 03:00 AM
Visual Programming Plugin for NT - Seeking beta testers Jeremytang NinjaScript File Sharing Discussion 0 02-24-2012 08:38 AM
Porting StrategyDesk Programming Code to NT borland General Programming 3 09-20-2009 02:49 PM
NT object model astrolobe General Programming 1 04-01-2009 07:58 AM
Need Help Programming Custom Indicator from TS to NT stevestrading Indicator Development 4 06-20-2007 04:31 PM


All times are GMT -6. The time now is 06:16 PM.