![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
Hello,
If I have an indicator that uses both OnBarUpdate and OnMarketData, and let’s say there is a sell and the price ticks down. This means that both of these methods will be triggered. I assume that OnMarketData will be triggered first and then the logic will jump to OnBarUpdate. Is this the case? Thanks, redduke |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
OnBarUpdate() only triggers off of last price. OnMarketData() triggers off of all market data events. OnBarUpdate() will trigger for every last price market data event fired. Although I suspect OnBarUpdate() is called second in most cases, you can not guarantee that.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
Hi Ray,
Thanks for the reply. I took a look at one of Ninja 6.5 indicators – BuySellVolume. It uses both of these methods. OnMarketData is used to calculate buy and sell volume and then OnBarUpdate plots it into display, so it is important for one to follow the other, which I assume it does based on your reply, it least in most cases. Regards, redduke |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
I have experienced a weird behavior today, when I tried to see how OnMarketData performs. Below is the code that I used:
protected override void OnBarUpdate() { Print(LastVolume); } protected override void OnMarketData(MarketDataEventArgs e) { if (e.MarketDataType == MarketDataType.Last) LastVolume = e.Volume; } When I opened Output window and placed it next to Time and Sales, I have notices that there was about 1-2 seconds delay of the LastVolume appearing there. In some cases it appeared at the same time as volume in T&S, but most of the time there was a small delay. Any idea why there is a lag? Thanks, redduke |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Is the Time and Sales set to refresh based on a timer? If yes, this would account for the delay.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
No, T&S is set to be refreshed with every tick, and it is the indicator with the logic below that lags. I thought that they should behave identically, am i wrong?
Thanks, redduke |
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
|
Thanks for clarification. Looks like OnBarUpdate() may trigger first before OnMarketData thus the event that is printing LastVolume is actually the next incoming tick.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
Ray,
Thanks for this info. This would explain another anomaly that I have seen. I have put BuySellVolume indicator on constant volume charts (200 volumes per bar), so I should have never seen BuySellVolume greater than 200 for each bar. However, this is exactly what happened. BuySellVolume showed volumes like 230, 220 and so on for some of the bars. Now since, OnMarketData is triggered after OnBarUpdate, it just grabbed the volume that was supposed to stay in the previous bar and added to the current bar as soon as current bar is created. Regards, redduke |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jan 2007
Location: , ,
Posts: 250
Thanks: 1
Thanked 2 times in 1 post
|
Hi Ray & RedDuke,
I have noticed the same issues with the interaction between OnMarketData and OnBarUpdate. If you add e.Time to your short example and then include the timestamp in the Print statement you will see that the delay you notice is actually a 1 trade lag. Not sure why this happens - any ideas Ray? |
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Apr 2007
Location: , ,
Posts: 105
Thanks: 1
Thanked 0 times in 0 posts
|
Hi Rt-trader,
OnMarkerData will be called whenever somethig changes on level1. OnBarupdate will be called only when there is a trade, in which case it will be called before OnMarketData. The solution that I found to be working is migrate most my indicator logic to OnMarketData. I am very excited since I can now capture time and sales in indicator without some not so perfect coding in OnBarUpdate. Regards, redduke |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| OnMarketData And Chart Update question | rt-trader | Historical NinjaTrader 6.5 Beta Threads | 2 | 11-29-2007 05:18 PM |
| OnMarketData() not working | Json | General Programming | 4 | 11-08-2007 04:09 AM |
| Drawing indicator outside of OnBarUpdate() | nvladik | Indicator Development | 1 | 06-21-2007 12:01 AM |
| Stateful OnBarUpdate | kgillis23 | General Programming | 2 | 05-30-2007 11:01 AM |
| Events Other Than OnBarUpdate | californiaruby | Automated Trading | 5 | 02-10-2007 08:30 AM |