• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to create custom class with access to NT's methods?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to create custom class with access to NT's methods?

    I have some questions about how best to organize my custom classes and methods so that they have access to NinjaScript's instance methods while still being able to create instances of my own class.

    I'm running into problems in creating a class that holds, imports, and exports bar data (BarDataIO). Specifically, I'm getting CS0038 or CS0120 errors because I'm either creating a new instance of it in OnBarUpdate() or moving it out of MyStrategy : Strategy and losing access to things like Close[0].

    Could you please provide some guidance and an outline of how and where to put custom classes within namespace NinjaTrader.NinjaScript.Strategies and MyStrategy : Strategy?

    I'm new to coding so I might be overlooking something simple like having to create a new instance of my strategy or inheriting from something else but I'm just guessing. I did create an instance of my strategy but then Close[0] seemed to be out of range...

    Thanks!

    #2
    Hello hillborne,

    May I ask for more details about what it is you are trying to do exactly? For example are you trying to access a data series calculated in an indicator via a strategy?

    Perhaps you could share the strategy/indicator you are working on so I may better answer your question.

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan,

      For a very minimal example (because I want to record and work with a lot more data) here is an example class:

      Code:
      public class BarDataIO
      	{
      		string message = "This is the information to write: ";
      			
      		int barNumber;
      			
      		public void Report()
      		{
      			barNumber = CurrentBar;
      			Print(message + barNumber);
      		}
      	}
      If I have it within MyStrategy : Strategy, I get CS0038 errors: Cannot access a non-static member of outer type 'NinjaTrader.NinjaScript.NinjaScriptBase' via nested type.

      If I move it out of MyStrategy, then CurrentBar, Close[0], Print, etc. don't have context or an object to work on.

      Any suggestions on how to create a 'data holding' class used to import/export bar data?

      Comment


        #4
        Hello hillborne,

        You should move the class outside your strategy class.

        Below is a link for an indicator I created which has a custom public class, (line 581 of the code), which stores data time and open interest data, for which you could reference.

        http://ninjatrader.com/support/forum...d=7&linkid=922

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Here is one of the ways:
          http://ninjatrader.com/support/forum...11&postcount=8
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by mbesha, Today, 09:26 AM
          0 responses
          1 view
          0 likes
          Last Post mbesha
          by mbesha
           
          Started by Brillo, Today, 08:58 AM
          0 responses
          4 views
          0 likes
          Last Post Brillo
          by Brillo
           
          Started by avrege, Today, 01:48 AM
          2 responses
          11 views
          0 likes
          Last Post avrege
          by avrege
           
          Started by markbb10, Today, 07:14 AM
          0 responses
          7 views
          0 likes
          Last Post markbb10  
          Started by leodrz, Today, 05:09 AM
          0 responses
          10 views
          0 likes
          Last Post leodrz
          by leodrz
           
          Working...
          X