Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Can I submit orders by time series

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

    Can I submit orders by time series

    Let's say my strategy conditions are met to place an order. My order size is 10 contracts. I want to split up the orders so that they get sent to the broker in 100 millisecond intervals, one contract at a time, regardless of the number of bar updates or ticks in that time period. Is this possible in a NinjaScript strategy?

    Bryan
    cassb
    NinjaTrader Ecosystem Vendor - Logical Forex

    #2
    Hello cassb, and thank you for your question. NinjaScript strategies are truly event driven. Tick data which drives the OnMarketData typically comes in more quickly than at 100 millisecond intervals, and DateTime.Now (rather than the time series) will allow you to determine whether 100 millisecond intervals have passed. Finally, the unmanaged order entry approach will give you greater flexibility and control over the timing trades are initialized. This is the extent of the built in support Ninja offers for what you are describing. Please let us know if there are any other ways we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      So the answer is that I am limited by the tick events that cause the OnBarUpdate or other routines to execute? And if the tick data comes in at great than 100 ms intervals, then it's not possible to force an order to go to the broker until the "next" tick is received by the strategy?
      cassb
      NinjaTrader Ecosystem Vendor - Logical Forex

      Comment


        #4
        There was one more method I missed mentioning in my post earlier that is directly supported by Ninja. I would like to invite you to see the TriggerCustomEvent documentation for timed events.



        Beyond this, MSDN C# does have some support available as well for firing events every 100 ms.

        As far as how quickly events are actually processed, even if they are sent off every 100 ms, NinjaTrader uses many different APIs with many different web resources and desktop applications. NinjaScript offers a single interface into all of these, but shares limitations with different APIs.

        The unmanaged order entry approach I mentioned earlier, documented here,



        allows you to initiate orders as quickly as you'd like and to take over control and responsibility for order handling when the trade desk sends feedback back to NinjaTrader through the OnOrderUpdate and OnExecution(Update NT8) methods. The Managed approach handles a lot of this logic for you, but the cost to this convenience is that you lose the flexibility you would need to try approaches like the approach you are suggesting.
        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          OK, thanks! I definitely want the Managed approach, so I'll have to work with its limitations. Thanks for the info!
          cassb
          NinjaTrader Ecosystem Vendor - Logical Forex

          Comment


            #6
            Originally posted by cassb View Post
            So the answer is that I am limited by the tick events that cause the OnBarUpdate or other routines to execute? And if the tick data comes in at great than 100 ms intervals, then it's not possible to force an order to go to the broker until the "next" tick is received by the strategy?
            Not quite. You can use a Timer object that you set up, and use it to do anything at any granularity.

            Comment


              #7
              Ah, OK that sounds awesome then. I totally forgot about a Timer, but I think I've used it before in NinjaScript. I'll look into it, thank you! Any example script that you know of that I can take a look at?
              cassb
              NinjaTrader Ecosystem Vendor - Logical Forex

              Comment


                #8
                Originally posted by cassb View Post
                Ah, OK that sounds awesome then. I totally forgot about a Timer, but I think I've used it before in NinjaScript. I'll look into it, thank you! Any example script that you know of that I can take a look at?
                I did have something like that, and I can certainly look around to see if I still have it hiding somewhere, but I am afraid that it may have been a victim of the fire that razed all my possessions a few years ago, but for pretty much only what I was carrying around my neck on a USB thumb drive and my travelling bag with my old laptop.

                Comment


                  #9
                  Originally posted by cassb View Post
                  Ah, OK that sounds awesome then. I totally forgot about a Timer, but I think I've used it before in NinjaScript. I'll look into it, thank you! Any example script that you know of that I can take a look at?
                  Found this. Should be easy enough to adapt to the NT framework.

                  You just need to split up the timer creation and assignation, event handler hookup and startup to the appropriate OnStateChange state.

                  Start the timer when your trade setup occurs, then send your orders based on the granularity that you want, and stop the timer.

                  https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

                  Comment


                    #10
                    Sheesh... I had a fire in Oct 2015 that destroyed all my computer equipment as well - started in the garage with smoldering wood ashes in a bucket. I luckily found a backup drive in the debris and paid $2500 to have it restored successfully.

                    And I just found out today that a co-worker also had a fire 3 years ago, started in the garage and destroyed all his woodworking tools. Weird coincidences!
                    cassb
                    NinjaTrader Ecosystem Vendor - Logical Forex

                    Comment


                      #11
                      This might help:

                      #region Using declarations

                      // add this

                      using System.Timers;

                      #endregion

                      #region Variables

                      // add this

                      private System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();

                      #endregion

                      // start your timer somewhere
                      timer.Tick += do_your_process; // name of your entry function
                      timer.Interval = 1000; // timer increment in milliseconds
                      timer.Start();

                      // don't forget to turn it off somewhere
                      timer.Stop();
                      timer.Tick -= do_your_process;

                      private void do_your_process(object sender, EventArgs e)
                      {
                      // your timer entry ... do something.
                      // yes you can have multiple timers: change timer to timer_1, timer_2, etc (with additional region variables to accommodate) ... with potentially different entry functions
                      }
                      Last edited by Bluepoint; 12-29-2016, 01:55 AM.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by traderqz, Yesterday, 12:06 AM
                      11 responses
                      27 views
                      0 likes
                      Last Post NinjaTrader_Gaby  
                      Started by PaulMohn, Today, 03:49 AM
                      0 responses
                      8 views
                      0 likes
                      Last Post PaulMohn  
                      Started by inanazsocial, Today, 01:15 AM
                      1 response
                      10 views
                      0 likes
                      Last Post NinjaTrader_Jason  
                      Started by rocketman7, Today, 02:12 AM
                      0 responses
                      11 views
                      0 likes
                      Last Post rocketman7  
                      Started by dustydbayer, Today, 01:59 AM
                      0 responses
                      4 views
                      0 likes
                      Last Post dustydbayer  
                      Working...
                      X