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

MarketDepthEventArgs - Clarification needed

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

    MarketDepthEventArgs - Clarification needed

    Hi,

    Could I please get some clarification on the details provided by http://www.ninjatrader-support.com/H...DepthEventArgs, specifically relating to the Operation property?

    The help guide states:
    Operation
    Represents the action you should take when building a level two book.

    Possible values are:

    Operation.Insert
    Operation.Remove
    Operation.Update
    Why does this refer to the action I should take when building my own order book? All I want is the event args to tell me what volume change has occured at what price level in the book.

    I've looked at the SampleMarketDepth example on these forums but am still unclear about under which exact circumstances this event gets fired, and the correct meaning/usage of the Operation (and Position) properties. For instance, does an event with e.Operation == Operation.Remove relate to the situation where a row has dropped off the top or bottom of the ladder, or when an order has been removed from the book?

    I'm guessing here that this API event is a wrapper for exposing some internal functionality related to the visual SuperDOM modules. Some help in understanding it would be gratefully appreciated.


    Thanks.
    Last edited by ScoobyStoo; 05-17-2009, 10:55 AM.

    #2
    This reference sample should help: http://www.ninjatrader-support2.com/...ead.php?t=3478

    Comment


      #3
      Originally posted by NinjaTrader_Dierk View Post
      Thanks Dierk. But as I said, I've looked at that sample and it doesn't actually explain much about the logic behind the event. It just gives you one example of how the event can be used, which isn't much help if you don't wish to use it in that way.

      Comment


        #4
        The example shows you how to build an order book which actually requires processing Insert, Update and Delete properly.

        Comment


          #5
          Originally posted by NinjaTrader_Dierk View Post
          The example shows you how to build an order book which actually requires processing Insert, Update and Delete properly.
          I think you are missing my point. I don't want to build an order book in the same way as featured in the example. What I need is a proper understanding of the underlying event model, not how to implement it for this one example scenario. The documentation is a little light in explaining exactly what the properties correspond to, and I need a completely clear understanding of what's going on.

          Could you have a look under the covers of NT's source code and just confirm exactly how these properties are set?

          Thanks

          Comment


            #6
            - Insert: insert record at .Position
            - Remove: remove record from .Position
            - Update: update record at .Position

            Unfortunately there isn't more information to provide.

            Comment


              #7
              OK, so I'll have a dig around myself to figure out how this works...

              I've just quickly created the following custom indicator and added it to a chart to check out the firing of events:

              namespace NinjaTrader.Indicator
              {
              /// <summary>
              /// Dumps event sequence
              /// </summary>
              [Description("Dumps event sequence")]
              public class DumpEventSequence : Indicator
              {
              protected override void Initialize()
              {
              Print("Initialize()");
              Print("Time : " + DateTime.Now.ToLongTimeString());
              Print(Environment.NewLine);

              CalculateOnBarClose = false;
              Overlay = false;
              PriceTypeSupported = false;
              }

              protected override void OnBarUpdate()
              {
              Print("OnBarUpdate()");
              Print("Time : " + DateTime.Now.ToLongTimeString());
              Print(Environment.NewLine);
              }

              protected override void OnMarketDepth(MarketDepthEventArgs args)
              {
              Print("OnMarketDepth()");
              Print("Time : " + DateTime.Now.ToLongTimeString());
              Print("MarketDataType : " + args.MarketDataType.ToString());
              Print("Operation : " + args.Operation.ToString());
              Print("Position : " + args.Position.ToString());
              Print("Price : " + args.Price.ToString());
              Print("Volume : " + args.Volume.ToString());
              Print(Environment.NewLine);
              }
              }
              }


              I've attached the output.

              Can you let me please why the indicator's Initialize method (which is supposed to be called once) is being called twice (at 4:29:10 PM and 4:29:15 PM) before the 10 levels of the DOM order book are built and then again once (at 4:29:17 PM) before the historical bars on the chart are processed?
              Attached Files

              Comment


                #8
                The Initialize() is expected to be called multiple times - http://www.ninjatrader-support.com/H...nitialize.html


                If your code is sensitive to being called multiple times, please move to another location such as OnBarUdpate() or OnMarketDepth() etc..
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Bertrand View Post
                  The Initialize() is expected to be called multiple times - http://www.ninjatrader-support.com/H...nitialize.html


                  If your code is sensitive to being called multiple times, please move to another location such as OnBarUdpate() or OnMarketDepth() etc..
                  Ok thanks.

                  Can I suggest you alter the indicator code template as it misleadingly states:

                  /// <summary>
                  /// This method is used to configure the indicator and is called once before any bar data is loaded.
                  /// </summary>
                  protected override void Initialize()


                  I'm pretty sure most developers new to NT will assume that any initialisation method is called only once upon initialisation of the object. This is a convention and I think you need to make it really clear in the code template that this is not the case.

                  P.S. Where should I place initialisation code then that I want called only once?

                  Comment


                    #10
                    There is a misunderstanding: Initialize() is called once PER INSTANCE of an indicator. As you configure an indicator/strategy multiple instances (some of them temporary) of the same indicator/strategy might be created.

                    Comment


                      #11
                      Originally posted by NinjaTrader_Dierk View Post
                      There is a misunderstanding: Initialize() is called once PER INSTANCE of an indicator. As you configure an indicator/strategy multiple instances (some of them temporary) of the same indicator/strategy might be created.
                      OK. I think I understand now. So for example, when a user brings up the indicators dialog box it creates an instance of every indicator in order to display their default properties (obviously), but the initialise() method is also called in these cases.

                      Is there an event/method that I can use to perform some expensive operations, which I only want performed when an indicator is actually added to a chart? I'm guessing not as I can't find anything in the manual.

                      Comment


                        #12
                        >> I'm guessing not
                        Correct -> you would need to code using some flag in OnBarUpdate or such.

                        Comment


                          #13
                          Originally posted by NinjaTrader_Dierk View Post
                          >> I'm guessing not
                          Correct -> you would need to code using some flag in OnBarUpdate or such.
                          Yeah. I had assumed that the object was constructed into order to display/set properties but was only initialised when the indicator was actually added to a chart.

                          Also, I have discovered that OnMarketData() is called before Initialize(), which is not made clear.

                          Tell you what, some documentation on the lifecycles of NT indicators and strategies would be really helpful. Are there any other gotchas like this I need to be aware of?

                          Comment


                            #14
                            My specific problem is that the OnMarketData() method is called 10 times to insert all 10 rows into the order book ladder before the Initialize() method is called.

                            I want to perform operations within the OnMarketData() method involving objects which I have initialised in the Initialize() method...but I am obviously unable to do this.

                            How do you recommend I work around this?

                            Comment


                              #15
                              OnMarketData() will NOT be called before Initialize().

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by cmtjoancolmenero, Yesterday, 03:58 PM
                              11 responses
                              39 views
                              0 likes
                              Last Post cmtjoancolmenero  
                              Started by FrazMann, Today, 11:21 AM
                              0 responses
                              5 views
                              0 likes
                              Last Post FrazMann  
                              Started by geddyisodin, Yesterday, 05:20 AM
                              8 responses
                              52 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Started by DayTradingDEMON, Today, 09:28 AM
                              4 responses
                              26 views
                              0 likes
                              Last Post DayTradingDEMON  
                              Started by George21, Today, 10:07 AM
                              1 response
                              22 views
                              0 likes
                              Last Post NinjaTrader_ChristopherJ  
                              Working...
                              X