• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Tomass, Yesterday, 11:52 PM
          0 responses
          2 views
          0 likes
          Last Post Tomass
          by Tomass
           
          Started by J_o_s, Yesterday, 11:31 PM
          0 responses
          6 views
          0 likes
          Last Post J_o_s
          by J_o_s
           
          Started by kirkvan, Yesterday, 09:03 PM
          0 responses
          7 views
          0 likes
          Last Post kirkvan
          by kirkvan
           
          Started by hedgeplay, Yesterday, 08:35 PM
          0 responses
          5 views
          0 likes
          Last Post hedgeplay  
          Started by jaboo, Yesterday, 06:38 PM
          0 responses
          12 views
          0 likes
          Last Post jaboo
          by jaboo
           
          Working...
          X