![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
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: OperationWhy 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 at 10:55 AM.
|
|
|
|
|
|
#2 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
This reference sample should help: http://www.ninjatrader-support2.com/...ead.php?t=3478
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#3 | |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
Quote:
|
|
|
|
|
|
|
#4 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
The example shows you how to build an order book which actually requires processing Insert, Update and Delete properly.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
Quote:
Could you have a look under the covers of NT's source code and just confirm exactly how these properties are set? Thanks |
|
|
|
|
|
|
#6 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
- Insert: insert record at .Position
- Remove: remove record from .Position - Update: update record at .Position Unfortunately there isn't more information to provide.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
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? |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,409
Thanks: 252
Thanked 975 times in 958 posts
|
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..
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 | |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
Quote:
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? |
|
|
|
|
|
|
#10 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
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.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
Quote:
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. |
|
|
|
|
|
|
#12 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
>> I'm guessing not
Correct -> you would need to code using some flag in OnBarUpdate or such.
Dierk
NinjaTrader Customer Service |
|
|
|
|
|
#13 | |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
Quote:
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? |
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Apr 2009
Posts: 161
Thanks: 0
Thanked 5 times in 5 posts
|
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? |
|
|
|
|
|
#15 |
|
Administrator
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
|
OnMarketData() will NOT be called before Initialize().
Dierk
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Clarification on IB connection | OLIVER97 | Connecting | 1 | 07-25-2008 06:21 AM |
| CalculateOnBarClose clarification | trader_rick | Automated Trading | 4 | 06-25-2008 09:01 AM |
| Clarification | Mike_32 | Installation and Licensing | 14 | 05-11-2008 01:49 PM |
| NT requirements clarification | newguy05 | Connecting | 3 | 02-11-2008 10:02 PM |
| Clarification of GetCurrentAskVolume() Method | Learning1 | General Programming | 8 | 08-14-2007 01:56 PM |