Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

CloseStrategy command in a Strategy

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

    CloseStrategy command in a Strategy

    I have a strategy that needs to exit if TickReplay is not enabled. In State.Configure I check for TickReplay:

    Code:
    else if (State == State.Configure)
    {
       if (!IsTickReplay)
       {
           Print("Tick replay must be enabled for this strategy to function.");
           SetState(State.Terminated);
         }
     }
    The state goes to terminated and I want the strategy to disable. In the docs under CloseStrategy it says it should:

    Cancels all working orders, closes any existing positions, and finally disables the strategy
    so in State.Terminated I put:

    Code:
    else if (State == State.Terminated) {
        CloseStrategy(null);
    }
    But the check box under the Enabled column the in Strategies tab in Control Center stays checked. Shouldn't CloseStrategy unset the checkbox as the strategy is now disabled as the docs say?

    I am using NT8 RC2 for reference.

    #2
    CloseStrategy() does not work >= State.Terminated. I'll request clarification in the help guide on that point.

    CloseStrategy() is for managing positions, in this scenario, there is nothing to manage and wouldn't suggest calling it since it does submit a close order.

    What you should do instead is throw and exception under the invalid configuration. This will not only finalize the strategy for you but will print the string you pass to the output and log tab.

    Code:
                else if (State == State.Configure)
                {
                    if(!TickReplay)
                        throw new Exception("Tick replay must be set to true");
                
                }
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thank you Matthew. I'll throw the exception as you recommended instead of using CloseStrategy.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Tim-c, Today, 10:58 AM
      0 responses
      1 view
      0 likes
      Last Post Tim-c
      by Tim-c
       
      Started by traderqz, Yesterday, 09:06 AM
      3 responses
      21 views
      0 likes
      Last Post NinjaTrader_ThomasC  
      Started by f.saeidi, Today, 10:19 AM
      1 response
      5 views
      0 likes
      Last Post NinjaTrader_BrandonH  
      Started by kujista, Today, 06:23 AM
      5 responses
      17 views
      0 likes
      Last Post kujista
      by kujista
       
      Started by traderqz, Today, 12:06 AM
      3 responses
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Working...
      X