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

Extract EnterLong EnterShort into Class

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

    Extract EnterLong EnterShort into Class

    Hi everyone,

    for a better reuse of my own entry strategy I want to extract EnterLong, EnterShort and other functions into an extra class.

    Unfortunately following is not working. Is there a way to get this working?

    Thanks in advance.

    Cheers



    HTML Code:
    public class myStrategy: Strategy
    {
    Ordermanager myOrders = new Ordermanager();
    
    
    protected override void OnBarUpdate()
    {
    
    myOrders.Long()
    
    }
    }
    
    public class Ordermanager : Strategy
    {
    public void Long()
    {
    var order = EnterLong(100, "name");
    }
    }

    #2
    Hello Airwave,

    Thank you for your reply.

    You'd want to create a partial class and put your reusable methods in there. How you have this currently is that you're essentially making 2 separate strategies, and strategies can't really talk to each other - you can't call a strategy from another strategy. I'd check out the section on Partial Classes on this page of our help guide:



    Please see the sample script at the following forum post that demonstrates.

    https://ninjatrader.com/support/foru...104#post457104

    Please let us know if we may be of further assistance to you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hello Kate,

      Thank you, that helped a lot.


      But still have following problems.

      I've created a shared class in the addons folder.
      In the class I have following (here simplified) code:


      namespace NinjaTrader.NinjaScript.Strategies
      {
      public partial class Strategy
      {
      public class Ordermanager
      {
      public void Long() {
      var order = EnterLong(100, "name");
      }
      }
      }
      }

      Unfortunetely I cannot access the EnterLong here?
      Error CS0120 An object reference is required for the non-static field, method, or property 'StrategyBase.EnterLong(int, string)' NinjaTrader.Custom


      Hope you can help me again.

      Cheers

      Comment


        #4
        Hello Airwave,

        Thank you for your reply.

        You may be missing some using declarations in your addon script (you'll need to expand this section at the top of your code to see them). I'm attaching a few example scripts that may be helpful in figuring out what may be missing. Make sure there's one for using NinjaTrader.NinjaScript;.

        Please let us know if we may be of further assistance to you.
        Attached Files
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by JonesJoker, 04-22-2024, 12:23 PM
        8 responses
        41 views
        0 likes
        Last Post JonesJoker  
        Started by timko, Today, 06:45 AM
        0 responses
        3 views
        0 likes
        Last Post timko
        by timko
         
        Started by Waxavi, 04-19-2024, 02:10 AM
        2 responses
        39 views
        0 likes
        Last Post poeds
        by poeds
         
        Started by chbruno, Yesterday, 04:10 PM
        1 response
        44 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Max238, Today, 01:28 AM
        1 response
        25 views
        0 likes
        Last Post CactusMan  
        Working...
        X