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 PeakTry, Today, 10:49 AM
      0 responses
      2 views
      0 likes
      Last Post PeakTry
      by PeakTry
       
      Started by llanqui, Today, 10:32 AM
      0 responses
      4 views
      0 likes
      Last Post llanqui
      by llanqui
       
      Started by StockTrader88, 03-06-2021, 08:58 AM
      45 responses
      3,992 views
      3 likes
      Last Post johntraderuser2  
      Started by TAJTrades, Today, 09:46 AM
      0 responses
      8 views
      0 likes
      Last Post TAJTrades  
      Started by rhyminkevin, Yesterday, 04:58 PM
      5 responses
      62 views
      0 likes
      Last Post dp8282
      by dp8282
       
      Working...
      X