![]() |
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: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
Hi,
I have noticed during some testing that OMD last price when used within OnBarUpdate lags Close[0] by 1 tick. I would have expected them to be identical at all times. The code I used to identify the situation is below - stripped down posting purposes (after testing it of course). In theory there should be no printing to the Output window, however, at every price change the print test is true. When compared against the Time & Sales window Close[0] is always correct. Any suggestions or comments? Hopefully I am wrong somewhere in my understanding or implementation - otherwise..... Thanks #region Variables private double lastprice = 0; private string ttime; #endregion protected override void Initialize() { CalculateOnBarClose = false; Overlay = true; PriceTypeSupported = false; } protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Last) { lastprice = e.Price; ttime = e.Time.ToLongTimeString(); } } protected override void OnBarUpdate() { if(!Historical) { if(Close[0] != lastprice) Print(Close[0] + " " + lastprice + " " + ttime); } } |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
There is no guarantee OnMarketData will trigger before OnBarUpdate. You can't compare it like that.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
A belated reply Josh - I will do some more testing around this...
Thanks... |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnMarketData and OnBarUpdate | svrz | Indicator Development | 6 | 12-23-2008 09:17 AM |
| OnBarUpdate() / OnMarketData() Priority | mrlogik | General Programming | 11 | 09-28-2008 05:00 PM |
| OnMarketData() vs. OnBarUpdate() | Tight Face | General Programming | 6 | 09-10-2008 02:20 PM |
| OnMarketData | SystemTrading | General Programming | 2 | 09-09-2008 04:51 PM |
| OnBarUpdate and OnMarketData used in one indicator? | RedDuke | General Programming | 9 | 12-14-2007 06:54 PM |