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 nailui, Today, 07:26 AM
          1 response
          28 views
          0 likes
          Last Post NinjaTrader_Spencer  
          Started by chartchartchart, Today, 08:08 AM
          1 response
          5 views
          0 likes
          Last Post NinjaTrader_Emily  
          Started by andreslazor7, Today, 08:08 AM
          3 responses
          15 views
          0 likes
          Last Post NinjaTrader_ChristopherJ  
          Started by FatCanary, Today, 08:09 AM
          2 responses
          9 views
          0 likes
          Last Post FatCanary  
          Started by vantojo, 01-12-2021, 02:13 PM
          15 responses
          197 views
          0 likes
          Last Post FatCanary  
          Working...
          X