Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

wait 10 seconds before submitting a market order

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

    wait 10 seconds before submitting a market order

    Hello,

    I am currently edeting my script to first submit a limit order and when it is not filled it will submit a market order. I used the layout from the SampleCancelOrder script provided on this forum. The script seems to work fine but it doesn't satisfy my needs yet.

    In this script it will cancel the limit order after a certain amount of bars closed. I am using 10 minute bars with my script and I don't want to wait a full 10 minutes before canceling the limit order and submitting the market order. I have already read about using the AAPL function and with that I can probably have my script wait 1 minute. (is that correct?) But in my preference I would like to have my script just wait a couple of seconds and no more. Will this be possible? And if yes, can you please help me on my way?

    Thanks a lot in advance,

    Sandor

    #2
    Supersaan,

    You could use a multi instrument strategy using a seconds data series, then just have it close your orders after a certain number of OnBarUpdates() for that series. Please find more information below.

    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Hello Adam,

      I am currently cracking my head on this script and I found out that the whole script stops working once I add PeriodType.Second to the Initialize() section. If I then change the "second" in to "minute" the script works again.
      Is it true that the secondary dataseries must be bigger then the primary for the script to work? Or is there another issue?

      Any help will be highly apreciated.

      Sandor

      Comment


        #4
        Instead use a time parameter like timespan etc like

        in variable
        TimeSpan ts;
        bool orderSubmitted = false;

        on bar update

        if (condition)
        {
        EnterLongLimit(....)
        ts = DateTime.Now.TimeOfDay;
        orderSubmitted = true;
        }

        if (orderSumbitted)
        {
        if (DateTime.Now.TimeOfDay.Subtract(ts).TotalSeconds > 10)
        {
        //change the order
        orderSubmitted = false;
        }
        }

        Comment


          #5
          Hi Bukkan,

          Thanks for putting me in the right direction. I can't find any additional info in the Help section of NT so I will post another question here. I can't get the TimeSpan woring since it is giving me error messages. I also use iOrders because of other functions in the script but I asume this should not be a problem. This is the script section wich I want to get working:

          private int ts = 10;


          protected override void OnBarUpdate()
          if (Position.MarketPosition == MarketPosition.Flat)
          {
          if (entryOrder == null && mar****rder == null && ENTRYCONDITION )
          {
          entryOrder = EnterLongLimit(0, true, 1, Low[0] - 5 * TickSize, "long limit entry");

          ts = DateTime.Now.TimeOfDay;
          }

          else if (entryOrder != null && DateTime.Now.TimeOfDay.Subtract(ts).TotalSeconds > 10)
          {
          CancelOrder(entryOrder);

          }
          }

          Can you please tell me what I do wrong here?

          Thanks a lot!

          Comment


            #6
            Originally posted by SuperSaan View Post
            Hi Bukkan,

            Thanks for putting me in the right direction. I can't find any additional info in the Help section of NT so I will post another question here. I can't get the TimeSpan woring since it is giving me error messages. I also use iOrders because of other functions in the script but I asume this should not be a problem. This is the script section wich I want to get working:

            private int ts = 10; //should be
            private TimeSpan ts; //its a private field so should be place in the variable section of the code.


            protected override void OnBarUpdate()
            if (Position.MarketPosition == MarketPosition.Flat)
            {
            if (entryOrder == null && mar****rder == null && ENTRYCONDITION )
            {
            entryOrder = EnterLongLimit(0, true, 1, Low[0] - 5 * TickSize, "long limit entry");

            ts = DateTime.Now.TimeOfDay;
            }

            else if (entryOrder != null && DateTime.Now.TimeOfDay.Subtract(ts).TotalSeconds > 10)
            {
            CancelOrder(entryOrder);

            }
            }

            Can you please tell me what I do wrong here?

            Thanks a lot!
            you also got to check that the order is not filled, if you are not using the bool as i showed in my previous post.

            Comment


              #7
              Hi Bukkan,

              First of all Happy thanksgiving!

              I edited the script exactly as you said but the if (DateTime...) function is not working while using the market replayer. It cancels the limit order directly after submitting, so it dowsn't wait 10 or 30 seconds. Below is the script I have today and I also added the Mar****rder section for you to judge. I can also confirm that the bool is working properly.

              if (Position.MarketPosition == MarketPosition.Flat)
              {
              if (entryOrder == null && mar****rder == null && ENTRYCONDITION )
              {
              entryOrder = EnterLongLimit(0, true, 1, Low[0] - 5 * TickSize, "long limit entry");

              ts = DateTime.Now.TimeOfDay;

              orderSubmitted = true;
              }
              }

              if (orderSubmitted)
              {
              if (DateTime.Now.TimeOfDay.Subtract(ts).TotalSeconds > 30)
              {
              CancelOrder(entryOrder);

              orderSubmitted = false;
              }
              }

              protected override void OnOrderUpdate(IOrder order)
              {
              if (entryOrder != null && entryOrder.Token == order.Token)
              {
              if (order.OrderState == OrderState.Cancelled)
              {
              entryOrder = null;

              mar****rder = EnterLong(1, "market order");
              }
              }
              }

              Thanks in advance!

              Sandor

              Comment


                #8
                there is a command like Account.Connection.Now (or something relating to the market data class) or something like that. I dont recall immediately but some unsupported nt stuffs which can be used in place of DateTime.Now

                Comment


                  #9
                  Hi Bukkan,

                  I can now confirm that the script is working, however I now run into a different problem. The script I use calculates on bar close and the "if (orderSubmitted)" was set in the onbarupdate() section of the script, wich is of course incorrect. Therefore it cancels the limit order on the bar update and not after a couple of seconds.

                  However I have no idea how to use the account.connection... condition properly with the script calculating on bar close. The only thing I can imagine is to set the calculateonbarclose on "false" and keep all my conditions and scripting (except the mar****rder) within the onbarupdate() section. Will this be the sollution to the problem? Or do you have a better idea?

                  Thanks again!

                  Sandor

                  Comment


                    #10
                    Originally posted by SuperSaan View Post
                    Hi Bukkan,

                    I can now confirm that the script is working, however I now run into a different problem. The script I use calculates on bar close and the "if (orderSubmitted)" was set in the onbarupdate() section of the script, wich is of course incorrect. Therefore it cancels the limit order on the bar update and not after a couple of seconds.

                    However I have no idea how to use the account.connection... condition properly with the script calculating on bar close. The only thing I can imagine is to set the calculateonbarclose on "false" and keep all my conditions and scripting (except the mar****rder) within the onbarupdate() section. Will this be the sollution to the problem? Or do you have a better idea?

                    Thanks again!

                    Sandor
                    put the relevant code in OnMarketData (see NT help files)

                    Comment


                      #11
                      Hi Bukkan,

                      It seems to be working perfectly fine now! Thanks a lot for all your help.

                      Sandor

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      647 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      369 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      108 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      572 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      573 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X