What is the best way to structuring custom classes? - NinjaTrader | futures io social day trading
futures io futures trading


What is the best way to structuring custom classes?
Updated: Views / Replies:2,122 / 4
Created: by shansen Attachments:4

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
 

What is the best way to structuring custom classes?

  #1 (permalink)
Elite Member
Melbourne, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 16 since Aug 2013
Thanks: 1 given, 4 received

What is the best way to structuring custom classes?

futures.io (formerly BMT) Forum,

My question would likely have been faced by most developers at some point. What is the best way to structure custom classes for quick writing, eased debugging, improved reliability & increased reusability?

I was of the understanding creating a new project for Business Logic (BL) (as per the attached screenshot) was the approach to take... now I'm not so sure. It is effective for creating custom classes which can be instantiated by classes within NT.Custom.Indicators. However, custom classes can not access properties (e.g. High[0], SMA(20)[0]) and methods from the class Indicator. What is the best way to structure custom code to access these properties from a project outside of the project NT.Custom? Alternatively, is there an entirely different approach I should be taking?

By way of example, the code (below and attached) compiles and runs. It demonstrates dependency inversion within the namespace NT.Indicator within the project NT.Custom. However, my problem presents where:
- a new project "NT.Custom.BL" is added to the solution NT.Custom
- a reference is added to the project "NT.Custom.BL" pointing to NT.Core
- a reference is added to the project "NT.Custom pointing" to "NT.Custom.BL" (within VS2013 and via the NinjaScript window within NT)
- the class SubClass (in the below code) is moved from the project NT.Custom to the project NT.Custom.BL.

As the reference added to NT.Custom points to NT.Custom.BL, a reference can not be added to NT.Custom.BL pointing back to NT.Custom. Without such a reference, NT.Custom.BL can not resolve the symbol 'StandardIndicator' in the constructor of the class SubClass. How can I appropriately access High[0] from a class outside of NT.Custom?

 
Code
namespace NinjaTrader.Indicator
{
  [Description("Enter the description of your new custom indicator here")]
  public class StandardIndicator : Indicator
  {
    private SubClass _subClass;

    protected override void Initialize()
    {
      Overlay = false;
    }

    protected override void OnStartUp()
    {
      _subClass = new SubClass(this);
    }

    protected override void OnBarUpdate()
    {
      var stdClassHigh = High[0];
      var subClassHigh = _subClass.GetHighUsingDependancyInversion();
      if (Math.Abs(stdClassHigh - subClassHigh) < 0.01)
        Print(stdClassHigh.ToString("n") + " = " + subClassHigh.ToString("n"));
    }
  }

  /* Unlike the class StandardIndicator, the class SubClass does not inherit from the class Indicator.  
   * As such, it can not access any methods or properties from the class Indicator or in turn IndicatorBase */ 
  public class SubClass
  {
    /* The GetHigh method does not compile.  
     * Can not resolve the symbol 'High' */
    public double GetHigh()
    {
      //return High[0];
      return 0.00;
    }
	
    /* Using Dependency Inversion, methods and properties from the class Indicator can be accessed.
     * This includes any methods in the class UserDefinedMethods. */
    private StandardIndicator _ind;

    public SubClass(StandardIndicator indicator)
    {
      _ind = indicator;
    }

    public double GetHighUsingDependancyInversion()
    {
      return _ind.High[0];
    }
  }
}
This has also been posted in the NT forum Undocumented/Unsupported Ninja Tips and Tricks #169 .

Thanks & regards
Shannon

Attached Thumbnails
What is the best way to structuring custom classes?-nt.custom.bl.png  
Attached Files
Register to download File Type: cs StandardIndicator.cs (5.1 KB, 22 views)
Reply With Quote
The following user says Thank You to shansen for this post:
 
  #2 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received

You can create your own classes outside of the Ninja Indicator namespace but inside the same file, this works fine and you can do anything you want in them. If they are public static they will be seen throughout all Ninja files.

You can cross reference any variables that are 'public' by prefixing them with the class name. e.g. myStuff.bugCount.

However, you should not expect to safely access internal Ninja event series without care. The 'TriggerCustomEvent' routine can be used to ease this, but the approach I prefer is to have OnBarUpdate write any values that I am interested in (e.g. High[0] or whatever) out to my class, rather than the other way around.

This way, and by making appropriate use of the 'lock' constructor, I can also safely run multithreaded systems inside Ninja, without risk to Ninja structures.

i haven't found much that can't be done inside the beast, which is of course it's phenomenal strength and it's weakness. Just like Windows.


Cheers

Travel Well
Reply With Quote
The following 3 users say Thank You to ratfink for this post:
 
  #3 (permalink)
Elite Member
Melbourne, Australia
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES
 
Posts: 16 since Aug 2013
Thanks: 1 given, 4 received


Ratfink & the futures.io (formerly BMT) Forum,

Thank you for your quick and knowledgeable reply.

I take your point on the dangers of attempting to access internal NT event series from outside the NT.Indicator namespace. By no means do I wish to complicate code and introduce the chance of it all going awry when money is on the line. Hence, my line of questioning.

I understand custom classes can be written outside of the NT.Indicator namespace but inside the same .cs file. However, this approach leads to the problem I am trying to overcome... excessively long files that become increasingly difficult to navigate. As the file become larger, it becomes less readable.

I am trying to divine a structure that improves readability by allowing for :
  1. Small, easily navigable files - Custom classes housed in separate .cs files, and
  2. Custom classes that can safely access properties (e.g. High[0], SMA(20)[0]) and methods from the Indicator class.
Where there is another approach that improves readability... I am all ears.

With this goal in mind, I would appreciate any input on the merits of two different approaches :
  1. Continuing from my earlier post, the Custom.BL project could include a"DataSeries" class which inherits from NT.Data.IDataSeries. From within an indicator OnBarUpdate event, appropriate values (e.g. High[0]) could be written to an instantiated "DataSeries" object. From there other classes in the Custom.BL project should be able to access the "DataSeries" values (I think). The structure would look like the attached screenshot "Custom.BL".
  2. I am clutching at straws here... If "BusinessLogic" was housed in the NinjaTrader.Custom project, would it be possible to have an indicator appropriately reference the custom classes and have the custom classes safely access indicator properties etc? How could this be achieved? This structure would look like the attached screenshot "BusinessLogic".

I am confident this problem has been encountered and solved by many people. Any ideas and insights are greatly appreciated.

Thanks again
Shannon

Attached Thumbnails
What is the best way to structuring custom classes?-custom.bl.png   What is the best way to structuring custom classes?-businesslogic.png  
Reply With Quote
 
  #4 (permalink)
Elite Member
Birmingham UK
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: IG/eSignal
Favorite Futures: Dax
 
ratfink's Avatar
 
Posts: 3,336 since Dec 2012
Thanks: 11,276 given, 7,090 received


shansen View Post
I understand custom classes can be written outside of the NT.Indicator namespace but inside the same .cs file. However, this approach leads to the problem I am trying to overcome... excessively long files that become increasingly difficult to navigate. As the file become larger, it becomes less readable.

Where there is another approach that improves readability... I am all ears.

Just use the preprocessor #region/#endregion directives, I use loads, problem goes away. Since NT always recompiles all files anyway no extra overhead for building, on an i7 huge files are done by the time the key press comes back up anyway.

e.g.:

 
Code
#region LOADSOFCODE

blah, blah, blah

#endregion
Once compiled, saved and reloaded whole region drops into a single line that you can just click on the left hand [+] to open or [-] to close. That's the route I use, but then I don't use any tools outside of Ninja for building or debugging.

I should also have said 'custom classes can be inside or outside Ninja namespaces, other problem solved if you go that route.

If you want to go the more sophisticated VS and external project route then @rleplae has just written an excellent piece on using external DLL's, see here : https://futures.io/ninjatrader-programming/32855-ninjatrader-dll-s-creating-loading-how.html#post428774

Cheers.

Travel Well

Last edited by ratfink; August 23rd, 2014 at 12:49 PM.
Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Orlando
 
Futures Experience: Advanced
Platform: NinjaTrader
Favorite Futures: Forex
 
Posts: 1 since Oct 2013
Thanks: 0 given, 0 received

Trying this

I'm having the same issue. I was able to avoid the compile error by having my class (CMyCustomClass) inherit from "Strategy" as shown below. Note, "steepness" is a function I defined in "UserDefinedMethods.cs". It seems like NT indicators like SMA will now work within my class methods.



#region Using declarations
#endregion

// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public class CMyCustomClass : Strategy
{
public void runMyCustomMethod(int barsAgo)
{
double steepness20 = steepness(barsAgo, 2, SMA(20));
double steepness10 = steepness(barsAgo, 2, SMA(10));
}
}
}

Reply With Quote

Reply



futures io > > > > What is the best way to structuring custom classes?

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
Custom database with custom tickers. Is it possible ? enjoyaol AmiBroker 4 March 28th, 2014 01:33 PM
Looking to pay someone to create many Custom Alerts & Custom Scans on ThinkOrSwim jasonbanash ThinkOrSwim Programming 1 January 30th, 2014 07:26 AM
NinjaTrader Namespaces Classes Methods etc tornadoatc NinjaTrader Programming 2 April 11th, 2013 02:35 PM
Where do you put your helper classes? balance NinjaTrader Programming 1 February 25th, 2013 11:49 AM
Custom development neb1998 NinjaTrader Programming 1 March 7th, 2011 04:43 PM


All times are GMT -4. The time now is 11:17 AM.

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-13 in 0.12 seconds with 20 queries on phoenix via your IP 54.227.51.103