Announcement

Collapse
No announcement yet.

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."
        https://ninjatrader.com/support/help...sestrategy.htm

        If you do not want to close the position, use SetState(State.Terminated) instead of CloseStrategy().
        https://ninjatrader.com/support/help...8/setstate.htm
        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 BarakSel, Today, 02:13 AM
          0 responses
          7 views
          0 likes
          Last Post BarakSel  
          Started by CarpetHooligan, Yesterday, 05:49 PM
          0 responses
          16 views
          0 likes
          Last Post CarpetHooligan  
          Started by EquityTrader, Yesterday, 03:33 PM
          0 responses
          15 views
          0 likes
          Last Post EquityTrader  
          Started by ahelton, Yesterday, 11:53 AM
          2 responses
          41 views
          0 likes
          Last Post ahelton
          by ahelton
           
          Started by tonynt, Yesterday, 02:07 PM
          0 responses
          22 views
          0 likes
          Last Post tonynt
          by tonynt
           
          Working...
          X