Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

What's the problem if I add enterLong() inside of Indicator() instead of Stragtegy()?

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

    What's the problem if I add enterLong() inside of Indicator() instead of Stragtegy()?

    https://ninjatrader.com/support/help...vel_ii_dat.htm has sample scripts for level 2 book. The book is implemented in the space of Indicator(). What if I add EnterLong() inside of OnBarUpdate() under Indicator()? Is this doable or I have to call EnterLong() under Strategy()? Thanks.

    #2
    Originally posted by localappleseed View Post
    What if I add EnterLong() inside of OnBarUpdate() under Indicator()?
    You should receive a compilation error.

    Originally posted by localappleseed View Post
    Is this doable or I have to call EnterLong() under Strategy()?
    Did you try it?
    The 'Indicator' class does not provide that method.

    Think about it:
    When your code does this,

    Code:
    namespace NinjaTrader.NinjaScript.[COLOR=#e74c3c]Indicators[/COLOR]
    {
       public class MyXXX : [COLOR=#e74c3c]Indicator[/COLOR]
       {
       ...
       }
    }
    your class 'MyXXX' inherits all the methods provided by the base class 'Indicator'.
    The 'Indicator' class does not have a method called 'EnterLong', so you should
    receive a compilation error if you do that.

    On other other hand,
    When your code does this,

    Code:
    namespace NinjaTrader.NinjaScript.[COLOR=#e74c3c]Strategies[/COLOR]
    {
       public class MyXXX : [COLOR=#e74c3c]Strategy[/COLOR]
       {
       ...
       }
    }
    your class 'MyXXX' inherits all the methods provided by the base class 'Strategy'.
    The 'Strategy' class does have a method called 'EnterLong', so no error occurs.

    Btw, the exact same class name 'MyXXX' is allowed -- this is not an error.
    Why? Because the two 'MyXXX' classes are in different namespaces.

    It's a bit confusing, because the base classes 'Indicator' and 'Strategy' provide
    a huge amount of overlap in the methods they provide -- for example, both
    classes have methods called 'Print', 'Alert', 'OnBarUpdate', etc etc.

    But only 'Strategy' provides the order methods.



    Comment


      #3
      Hello localappleseed,

      Thanks for your post.

      Member bltdavid has provided a comprehensive reply (Thank-you)

      To confirm, you do need to be in a strategy to use the Entry methods.

      Comment


        #4
        Thank you very much for your detailed answer!

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        63 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        139 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X