![]() |
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
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
|
If I create 3 Tick DataSeries as in the following code snippet, why would the count of the number of Closes in each series be different?
Initialize(): Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Last); //idx 1 Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Bid); //idx 2 Add(Instrument.FullName, PeriodType.Tick, 1, MarketDataType.Ask); //idx 3 OnStartUp() or OnBarUpdate(): Print("Closes[1].Count: "+Closes[1].Count+" Closes[2].Count: "+Closes[2].Count+" Closes[3].Count: "+Closes[3].Count); reports: Closes[1].Count: 331443 Closes[2].Count: 625472 Closes[3].Count: 610226 What am I missing? |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
CriticalTrader,
The bid, ask and last prices are all updated individually essentially. This is expected behavior. The bid price can change when the ask doesn't, and the last price is basically the "last traded price".
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
|
So how can I determine the size of the last trade as being on the bid or ask price if the Times are all identical? Is this also the case with the realtime OnMarketData MarketDataEventArgs data?
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
CriticalTrader,
OnMarketData is guaranteed to be called in sequence of how Bid/Ask/Last are received from your data provider. http://www.ninjatrader.com/support/h...marketdata.htm You could see if you have a bid or ask before a last for example in this case by keeping track of what MarketDataType the previous update was.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
|
Okay, but I'm attempting to create a historical view of the bid/ask volume and it seems quite problematic.
DataSeries doesn't even make sense to me. For instance, with the 3 DataSeries as in my initial post I have this snippet in OnBarUpdate(): if (BarsInProgress == 1) { int i = 0; if (CurrentBar == 1)}Print("OnBarUpdate 1: CurrentBar = "+CurrentBar+" Time[0] = " + Time[0] + " Close[0] = " + Close[0] + " Times[2].Count = " + Times[2].Count);while Generates following output. Notice the Error when i=2, well below Count. OnBarUpdate BEORE LOOP: CurrentBar = 1 Time[0] = 6/24/2012 6:00:00 PM Close[0] = 1325.5 Times[2].Count = 2817 OnBarUpdate IN LOOP: Times[2][0] =6/24/2012 6:00:00 PM Closes[2][0] = 1325.5 Volumes[2][0] = 229 OnBarUpdate IN LOOP: i = 1 OnBarUpdate IN LOOP: Times[2][1] =6/24/2012 6:00:00 PM Closes[2][1] = 1325.5 Volumes[2][1] = 232 OnBarUpdate IN LOOP: i = 2 Error on calling 'OnBarUpdate' method for indicator 'CDA_VolumeProfile_v232' on bar 1: Bar index needs to be greater/equal 0 |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
CriticalTrader,
DataSeries are like the data structure known as lists. They get an element added as its available from the data provider. Each one of the data series in a multi-series script isn't guaranteed to have the same number of elements. It helps to download the historical data for example in another chart to increase the availability of second or third added data series, etc. Ticks come in asynchronously in time. There is no way to guaranteed one tick will have the same exact time stamp as another tick because these come in sporadically based on when the price changes. The price doesn't change in set time intervals because people trading don't place orders at set time intervals. There may be 100 ticks one minute, and only 10 the next depending on how many people are participating in the market.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Member
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
|
Thanks AdamP. I understand now why the data series wouldn't have same number of elements.
I also understand the data in the bid/ask/tick are stored as they arrive asynchronously. But I'm not sure your response actually answers my question. My only point in the last example is that if the Close[2] data series has 625472 elements, then why would selecting Closes[2][2] result in an error? Is it because I'm accessing that element within the BarsInProgress==1 and CurrentBar==1 event and Closes[2][2] may not have arrived yet, even though this is historical data and not realtime data? |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
CriticalTrader,
Basically, indicators/strategies will start at the most-historical bar, then iterate forward through historical data until it reaches the most current bar. When you are on this "most-historical" bar there won't exist a bar before it, so it causes the error. You can check for CurrentBars[X] > 1 for example and it should work.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
|
A light just went off and I now realize my mistake in thinking. I was forgetting the Closes[2][2] wasn't accessing the third sequential element in series 2, but rather the element that was 2 bars ago! Unbelievable. Thanks for your patience Adam.
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
|
CriticalTrader,
No problem, we're happy to help. Yes, these dataseries act like lists with any new element being added getting assigned an index of 0, and all other element's indexes get increased by 1.
Adam P.
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Senior Member
|
Hello.
I want to display the last price on the chart. What is the proper syntax for the following? DrawHorizontalLine("Last Price",false,???,LineColor,HorizLineStyle,line_siz e); What should I replace ??? with to display the last traded price? |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
|
rcsingleton, that would be simply Close[0] with CalculateOnBarClose set to false for your indicator / script.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Senior Member
|
That's what I originally had and it wasn't working, so I thought there was a different syntax. I see two things now.
One, the "CalculateOnBarClose = false;" statement was not the final statement in the protected override void Initialize(). Two. Because of that, I see that CalculateOnBarClose = true was applied when the indicator was put on the chart. I've got it now. Thanks. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| DataSeries.Count | dom993 | General Programming | 8 | 05-08-2012 11:10 AM |
| tick count on LineBreak | photog53 | Indicator Development | 5 | 01-06-2012 03:15 PM |
| find the tick count on LineBreak | photog53 | Indicator Development | 0 | 06-07-2011 11:56 AM |
| tick count | madLyfe | Indicator Development | 1 | 05-24-2011 05:39 PM |
| tick count | kuroro13 | Charting | 2 | 08-08-2008 07:43 AM |