Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Calling Strategy methods from another class

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

    Calling Strategy methods from another class

    Hello,

    I'm new to NinjaTrader and NinjaScript, but have some programming background in c#.
    As far as I can see all the methods are incapsulated into Strategy class
    I wonder if I can do something like:
    Code:
    public class MyStrategy : Strategy
    {
        protected override void Initialize()
        {
              Class1 c1 = new Class1(this);
              c1.DoSmth();
        }
    }
    
    public class Class1 
    {
        private readonly Strategy _strategy;
        public Class1(Strategy strategy)
        {
            _strategy = strategy;
        }
    
        public void DoSmth()
        {
              _strategy.EnterLong();
        }
    }

    #2
    Hello qwerty_2004,
    Welcome to the forum and I am happy to assist you.

    NinjaScript is essentially C# and you will be able to use any method/rules which are applied to C#.

    You can take reference to this member submitted code;



    However please do note, we offer support for documented NinjaScript codes only (as found in our help guide) and any advanced C# concepts is not officially supported by us.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you NinjaTrader_Joydeep for example code,
      But this is not exactly what i wanted to know.

      I want to figure out if NinjaScript API functions are declared as 'public' (so I can use them from external classes)

      Comment


        #4
        Hello qwerty_2004,
        NinjaScript strategies are public classes and you will be able to call them from external classes.
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          Thanks a million!
          Will carry on involving

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          12 views
          0 likes
          Last Post sarafuenonly123  
          Started by Brevo, Today, 01:45 AM
          0 responses
          9 views
          0 likes
          Last Post Brevo
          by Brevo
           
          Started by aussugardefender, Today, 01:07 AM
          0 responses
          5 views
          0 likes
          Last Post aussugardefender  
          Started by pvincent, 06-23-2022, 12:53 PM
          14 responses
          242 views
          0 likes
          Last Post Nyman
          by Nyman
           
          Started by TraderG23, 12-08-2023, 07:56 AM
          9 responses
          387 views
          1 like
          Last Post Gavini
          by Gavini
           
          Working...
          X