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

Strategy not getting disabled in the grid after calling CloseStrategy()

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

    Strategy not getting disabled in the grid after calling CloseStrategy()

    I'm having difficulty with CloseStrategy(), it is not getting disabled after being called.

    There are 2 instances running and I'm trying to close the newly created 2nd instance if it detects that there is already an instance running on the same instrument (the detection code I work runs fine)

    what could be preventing it from getting disabled after CloseStrategy() is called?

    #2
    Hello NinjaCustomer,
    Thanks for your post.

    For starters, the notes in the help guide document describe a few reasons this method might not work as expected.
    From the help guide: https://ninjatrader.com/support/help...sestrategy.htm
    •If you choose to override this method using custom logic, the default behavior of the CloseStrategy() method will NOT be executed. For this reason, it is suggested to call the base implementation of CloseStrategy() method within the virtual override to ensure that the strategy is terminated as designed, otherwise it is your responsibility to correctly manage any working orders or positions.

    •CloseStrategy() will work of the current strategy position and will not factor in any StartBehavior setting, i.e. calling CloseStrategy() while the script is in a virtual historical position could result in an unwanted position

    •The default CloseStrategy() handling will only be applied to the primary series of a MultiSeries NinjaScript strategy.
    Another possibility is your "detection" code may not be working how you think it is.

    Can we see all the code that is relevant to "detecting" and using CancelOrder()?
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      I don't think it applies to my case because I don't override CloseStrategy(), I simply call it. I also don't have secondary data series. I'm not calling CancelOrder().. I'm just trying to tell the Strategy to quit .. when it does checks in the OnStateChange `else if (State == State.Configure)` block.

      Perhaps this is not the way to disable a strategy if checks fail? Also I set a class-level flag (bool closing) when this happens so that in OnBarUpdate() and other such events they just return immediately if 'closing' is set

      unfortunately my "detection" code is not accessible right now, I'm a bit new to using visual studio and I stashed the changes for now - while the market is open I don't want to mess with unstable code.. but I'm not really sure how to view stashed code. But the detection code did seem to work because I was verifying that both with print statements and breakpoints before.

      Comment


        #4
        NinjaCustomer,

        Whenever you get access to that code again please post it here so that I can assist further.
        Josh G.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by DJ888, Today, 10:57 PM
        0 responses
        1 view
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by MacDad, 02-25-2024, 11:48 PM
        7 responses
        158 views
        0 likes
        Last Post loganjarosz123  
        Started by Belfortbucks, Today, 09:29 PM
        0 responses
        7 views
        0 likes
        Last Post Belfortbucks  
        Started by zstheorist, Today, 07:52 PM
        0 responses
        7 views
        0 likes
        Last Post zstheorist  
        Started by pmachiraju, 11-01-2023, 04:46 AM
        8 responses
        151 views
        0 likes
        Last Post rehmans
        by rehmans
         
        Working...
        X