Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Cancel GTCs When Strategy is Canceled

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

    Cancel GTCs When Strategy is Canceled

    Hello,

    Is there a way to pull orders when a running strategy file is removed? I am already using CancelOrder() for certain events, just am unsure how to have a strategy pull orders upon being deleted.

    Thank you!

    Last edited by ozziyhtomit; 11-03-2020, 10:32 AM.

    #2
    Hello ozziyhtomit,

    Thank you for your post.

    You could certainly tell the strategy to exit any open positions when it reaches State.Terminated when the strategy is disabled. Here's a very simple example:

    Code:
     protected override void OnStateChange()
    {
    if (State == State.SetDefaults)
    {
    Description = NinjaTrader.Custom.Resource.NinjaScriptStrategyDes criptionSampleMACrossOver;
    Name = "ExampleCloseStrategy";
    Fast = 10;
    Slow = 25;
    // This strategy has been designed to take advantage of performance gains in Strategy Analyzer optimizations
    // See the Help Guide for additional information
    IsInstantiatedOnEachOptimizationIteration = false;
    }
    else if (State == State.DataLoaded)
    {
    
    }
    else if(State == State.Terminated)
    {
    if(Position.MarketPosition == MarketPosition.Long)
    ExitLong();
    }
    }
    
    protected override void OnBarUpdate()
    {
    if (State == State.Historical)
    return;
    if (CurrentBar < BarsRequiredToTrade)
    return;
    
    if(Close[0] > Open[0])
    EnterLong();
    
    }
    This would enter a trade on the first up bar in real time. It will only exit the trade when the strategy is disabled and reaches State.Terminated.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Actually I'm talking about deleting resting UNFILLED orders. But this looks like a solution for exiting positions AND pulling resting orders as well, yes?

      Thanks

      Comment


        #4
        Hello ozziyhtomit,

        Thank you for your reply.

        Yes, you should be able to call CancelOrder() in State.Terminated as well to cancel any working orders.

        Please let us know if we may be of further assistance to you.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        44 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        124 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        65 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        42 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X