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 rajendrasubedi2023, Today, 09:50 AM
          0 responses
          7 views
          0 likes
          Last Post rajendrasubedi2023  
          Started by ender_wiggum, Today, 09:50 AM
          0 responses
          3 views
          0 likes
          Last Post ender_wiggum  
          Started by bmartz, Today, 09:30 AM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          24 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by lorem, Today, 09:18 AM
          1 response
          5 views
          0 likes
          Last Post lorem
          by lorem
           
          Working...
          X