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

CloseStrategy Fires Late When Overridden

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

    CloseStrategy Fires Late When Overridden

    I'm using the CloseStrategy procedure in a NinjaScript strategy, and I've noticed that the procedure fires at different times if it isn't/is overridden, as follows:

    1. If CloseStrategy isn't overridden, then when the procedure is called it fires on the very next tick, while
    2. If CloseStrategy is overridden, then when the procedure is called it doesn't fire until the first tick of the next bar.

    What can I do to make my overridden CloseStrategy fire immediately (that is, on the very next tick)? If this isn't currently possible, then might the NT developers provide an enhancement to make it possible in the future?

    #2
    Hello NtFan,

    I have created a test script to test this and I was not able to reproduce.

    The test script will close the strategy on the first real-time market data update (so is designed to immediately disable in real-time and send a message to the output window)

    Please import this test script and run the script on a 1 day bar during market hours.

    On your end is this test script staying enabled when enabled during market hours?
    Attached Files
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your help with this, ChelseaB. I'm having trouble coding a simple strategy that demonstrates the problem, but I'll keep trying. To this end, I have a related question about overriding the CloseStrategy procedure. If I override CloseStrategy so that it looks like this...

      public override void CloseStrategy(string signalName)
      {
      }

      then, when this instance of CloseStrategy is called from OnBarUpdate, should it successfully disable the strategy? If the answer is no, then what code should I add to the overridden procedure to disable the strategy, but not cancel orders nor close positions?

      Comment


        #4
        Hello NtFan,

        Yes, calling CloseStrategy() from OnBarUpdate() would close the strategy.

        I chose to do this from OnMarketData() in the test script as this would only occur in real-time on the first tick.

        Attached is the same script with the code in OnBarUpdate() and triggered on the first tick of a bar in real-time.

        CloseStrategy() is designed to:
        "Cancel all working orders, closes any existing positions, and finally disables the strategy."


        If you do not want to close the position, use SetState(State.Terminated) instead of CloseStrategy().
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          SetState(State.Terminated) is precisely what I need, ChelseaB, and it works perfectly for me. Thanks very much for your help!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by helpwanted, Today, 03:06 AM
          1 response
          10 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