• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting Market Depth volume into strategy.

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

    Getting Market Depth volume into strategy.

    I’m trying to develop a strategy using the information of the market depth. For the moment I’m just trying to get the volume information of each level using the function: “OnMarketDepth(MarketDepthEventArgs e) and print it out to compare it with the SuperDOM information. The problem is that this function is obtaining the data on each update of any level of bid or ask order, and when the activity is very fast and more than one level is updating the data at the same time, the information is different from the SuperDOM. You can see in the attached image that the information is correct for the Corn future (left side) which is moving slow, but is not correct for the S&P500, which is moving very fast.

    Is there any way to get the information faster changing the code below (or attached)?

    The problem is that I'm getting the volume of each level one at a time and this process is too slow


    ********** CODE ************************************************** *****
    protected override void OnMarketDepth(MarketDepthEventArgs e)
    {
    if (e.Operation == Operation.Update)
    {
    if (e.MarketDataType == MarketDataType.Ask && e.Position == 0) VolAskL0 = e.Volume;
    if (e.MarketDataType == MarketDataType.Ask && e.Position == 1) VolAskL1 = e.Volume;
    if (e.MarketDataType == MarketDataType.Ask && e.Position == 2) VolAskL2 = e.Volume;
    if (e.MarketDataType == MarketDataType.Ask && e.Position == 3) VolAskL3 = e.Volume;
    if (e.MarketDataType == MarketDataType.Ask && e.Position == 4) VolAskL4 = e.Volume;

    if (e.MarketDataType == MarketDataType.Bid && e.Position == 0) VolBidL0 = e.Volume;
    if (e.MarketDataType == MarketDataType.Bid && e.Position == 1) VolBidL1 = e.Volume;
    if (e.MarketDataType == MarketDataType.Bid && e.Position == 2) VolBidL2 = e.Volume;
    if (e.MarketDataType == MarketDataType.Bid && e.Position == 3) VolBidL3 = e.Volume;
    if (e.MarketDataType == MarketDataType.Bid && e.Position == 4) VolBidL4 = e.Volume;

    VolAskTot = VolAskL0 + VolAskL1 + VolAskL2 + VolAskL3 + VolAskL4;
    VolBidTot = VolBidL0 + VolBidL1 + VolBidL2 + VolBidL3 + VolBidL4;

    Print("ASK Levels | L0:" + VolAskL0 + " | L1: " + VolAskL1 + " | L2: " + VolAskL2 + " | L3: " + VolAskL3 + " | L4: " + VolAskL4 + " | TOT: " + VolAskTot);
    Print("BID Levels | L0:" + VolBidL0 + " | L1: " + VolBidL1 + " | L2: " + VolBidL2 + " | L3: " + VolBidL3 + " | L4: " + VolBidL4 + " | TOT: " + VolBidTot);
    }
    }
    Attached Files

    #2
    Hello blackhawk,

    Thank you for your post.

    I will investigate this matter further on my end and follow up with you here when I have additional information.
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hello blackhawk,

      Thank you for your patience.

      There is a delay to the secondary depth levels on the SuperDOM (somewhere between .25 to .5 a second). This is for all secondary Level II levels in windows in the NinjaTrader 7 application. The OnMarketDepth() method would not see this delay.
      Patrick H.NinjaTrader Customer Service

      Comment


        #4
        #region Using declarations
        using System;
        using System.ComponentModel;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.Xml.Serialization;
        using NinjaTrader.Cbi;
        using NinjaTrader.Data;
        using NinjaTrader.Indicator;
        using NinjaTrader.Gui.Chart;
        using NinjaTrader.Strategy;
        #endregion

        // This namespace holds all strategies and is required. Do not change it.
        namespace NinjaTrader.Strategy
        {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class MyCustomStrategyz : Strategy
        {
        #region Variables
        // Wizard generated variables
        private int myInput0 = 1; // Default setting for MyInput0
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
        CalculateOnBarClose = false;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected void OnMarketData(MarketDataEventArgs e)
        {
        if (e.Operation == Operation.Update)

        if (e.MarketDataType == MarketDataType.Ask && e.Position == 0) VolAskL0 = e.Volume;
        if (e.MarketDataType == MarketDataType.Ask && e.Position == 1) VolAskL1 = e.Volume;
        if (e.MarketDataType == MarketDataType.Ask && e.Position == 2) VolAskL2 = e.Volume;
        if (e.MarketDataType == MarketDataType.Ask && e.Position == 3) VolAskL3 = e.Volume;
        if (e.MarketDataType == MarketDataType.Ask && e.Position == 4) VolAskL4 = e.Volume;

        if (e.MarketDataType == MarketDataType.Bid && e.Position == 0) VolBidL0 = e.Volume;
        if (e.MarketDataType == MarketDataType.Bid && e.Position == 1) VolBidL1 = e.Volume;
        if (e.MarketDataType == MarketDataType.Bid && e.Position == 2) VolBidL2 = e.Volume;
        if (e.MarketDataType == MarketDataType.Bid && e.Position == 3) VolBidL3 = e.Volume;
        if (e.MarketDataType == MarketDataType.Bid && e.Position == 4) VolBidL4 = e.Volume;

        VolAskTot = VolAskL0 + VolAskL1 + VolAskL2 + VolAskL3 + VolAskL4;
        VolBidTot = VolBidL0 + VolBidL1 + VolBidL2 + VolBidL3 + VolBidL4;


        if (VolAskTot/VolAskTot >= 1.1 )
        EnterLong(4);

        if (VolAskTot/VolAskTot <= 0.9 )
        EnterShort(4);
        }
        #region Properties
        [Description("")]
        public int MyInput0
        {
        get { return myInput0; }
        set { myInput0 = Math.Max(1, value); }
        }
        #endregion
        }
        }


        Cannot get this to compile... what am I missing. Just a newbie at coding. However you were asking exactly what I want, blackhawk. I want the cumulative bids and asks of the first 5 levels. So I can compare them and find some sort of momentum.

        Comment


          #5
          Hi Rhyshaelkan, I found some errors in you code that you need to correct to make your code work.
          I paste the changes below in red color.

          //Change nr 1: You need to add red color sentence inside Using declarations

          #region Using declarations
          using System.Linq;
          #endregion

          //Change nr 2: You need to add red color sentences inside region Variable

          #region Variables
          // Wizard generated variables
          privateint myInput0 = 1; // Default setting for MyInput0
          // User defined variables (add any user defined variables below)
          long VolAskL0;
          long VolAskL1;
          long VolAskL2;
          long VolAskL3;
          long VolAskL4;
          long VolBidL0;
          long VolBidL1;
          long VolBidL2;
          long VolBidL3;
          long VolBidL4;
          long VolAskTot;
          long VolBidTot;
          #endregion

          //Change nr 3: You need to change red color text of this function


          protectedvoid OnMarketData(MarketDepthEventArgs e)

          Comment


            #6
            Thank you greatly for the help.

            Comment


              #7
              Is there anything wrong with my logic?

              if ((VolAskTot/VolBidTot) >= multiplier )
              EnterLong(quantity);

              if ((VolBidTot/VolAskTot) >= multiplier )
              EnterShort(quantity);

              The script does not seem to be executing orders the way I think they should.

              Once I get it to start executing orders then I can alter the multiplier for optimal entry point, and adjust the exit strategy ATM for best results. First things first.
              Attached Files
              Last edited by Rhyshaelkan; 08-17-2014, 05:51 PM.

              Comment


                #8
                Hello Rhyshaelkan,

                Thank you for your post.

                What is you intended result of the code?

                Try printing the value of VolBidTot and VolAskTot: http://www.ninjatrader.com/support/h.../nt7/print.htm

                After printing are the values as expected in the Output window (Tools > Output)?
                Patrick H.NinjaTrader Customer Service

                Comment


                  #9
                  I tried testing the strategy posted below by Rhyshaelkan after compiling it, it does not show up in the list when i want to add it on the strategies tab under control panel. How can i add it to that menu? If it cant be added there , then how would i run this strategy?

                  Comment


                    #10
                    Hello,

                    Although the name of the file is MyCustomStrategy, the actual class (the strategy) is affectionately named "meowmix." Do you see meowmix in the list?
                    Dave I.NinjaTrader Product Management

                    Comment


                      #11
                      Hi Dave,

                      Thanks i do see meowmix. Another question i had was if this is live even driven data from level2 then why is there an option to choose from last minute bars etc in the menu before applying the stratgy in the control panel?

                      Comment


                        #12
                        These settings are important so that the strategy knows what interval to use for the data series (the data set of the bars). If the strategy is looking 5 bars back for a certain indicator value, for example, it will need to know how long each bar is so that it knows where to look. This is also important for analyzing price action, such as the High price of several bars ago, etc.
                        Dave I.NinjaTrader Product Management

                        Comment


                          #13
                          I understand why this is important but for this particular strategy it shouldn't Matter which settings are used correct? They should provide the same results as its just using live level 2 depth and not receiving based on bars or ticks right?

                          Originally posted by NinjaTrader_Dave View Post
                          These settings are important so that the strategy knows what interval to use for the data series (the data set of the bars). If the strategy is looking 5 bars back for a certain indicator value, for example, it will need to know how long each bar is so that it knows where to look. This is also important for analyzing price action, such as the High price of several bars ago, etc.

                          Comment


                            #14
                            Yes, that is correct. Since this strategy is only working with L2 data, the bar interval should be irrelevant, but the options will still be there in the Strategies window.
                            Dave I.NinjaTrader Product Management

                            Comment


                              #15
                              Hello,

                              I am testing the strategy posted below on the CL contract and have it running but its not executing any trades? I see 'Error on calling 'OnMarketDepth' method for strategy 'meowmix/......': Attempted to divide by zero" as the e.volume is first not storing in the variables and showing up as 0. The DOM shows different volume at each level but its only picking up one volume for every single level and VolAskTot gets that same value and VolBidTot gets 0.

                              This is what the output window is showing. Why are the volume levels only showing one value as well as why is it not storing in the variables?

                              Attached is the output im getting

                              Please help on how to fix this

                              Thanks
                              Attached Files
                              Last edited by Lisa1980; 06-01-2015, 10:29 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by pjsmith, Today, 05:21 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post pjsmith
                              by pjsmith
                               
                              Started by gbux11, Today, 02:41 AM
                              2 responses
                              9 views
                              0 likes
                              Last Post MicroTrends  
                              Started by Tiang, Today, 04:23 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post Tiang
                              by Tiang
                               
                              Started by TazoTodua, Today, 01:50 AM
                              0 responses
                              6 views
                              0 likes
                              Last Post TazoTodua  
                              Started by lonestar, Today, 01:42 AM
                              2 responses
                              7 views
                              0 likes
                              Last Post lonestar  
                              Working...
                              X