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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    55 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    132 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    73 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X