Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

introduce a delay between cancel order and submit a new one

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

    introduce a delay between cancel order and submit a new one

    in my strategy (managed method) I have a situation where I need to cancel an open order and replace it with a new one,
    sometimes its just a change of price but sometimes its also change the direction from buy to sell for example.

    I send a cancel order before sending a new order. But it seams the cancel confirmation takes some time and so the submission of a new order is premature.
    I understand that the managed method does not allow the change of direction if we have an open order.

    So I am thinking I need some SLEEP / delay put in between the cancel and the new order Enter() command. while I process the bar.
    I am looking to have a delay of some milliseconds. I am working with hourly bars so I think its shouldn't affect the process.

    also I am running the same strategy simultaneously on several stocks , so I am not sure that the definition of the system timer is the same for all strategies ?!

    I was looking at the

    Code:
    System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer {Interval = 100};
        timer.Tick += delegate
        {
            timer.Stop(); // make sure to stop the timer to only fire ones (if desired)
            timer.Dispose(); // make sure to dispose of the timer
        };
        timer.Start(); // start the timer immediately following the "before" logic
    also read this : https://ninjatrader.com/support/help...ustomevent.htm

    I am not sure that I am doing it right.

    can you please assist how should I do that ? some direction how to define this timer and use it inside the OnBarUpdate ()


    #2
    Hello dadarara,

    Thanks for your post.

    I've attached an example that will help with your general timer questions.

    Instead of a delay, you should use OnOrderUpdate() to look for OrderState.Cancelled as that would be more appropriate than trying to time a variable (internet/exchange speeds).

    DelayedEvents.zip

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X