NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 06-24-2012, 08:16 AM   #1
CriticalTrader
Member
 
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
Question Bid/Ask/Last Tick DataSeries Count

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?
CriticalTrader is offline  
Reply With Quote
Old 06-24-2012, 02:24 PM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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".
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-24-2012, 04:09 PM   #3
CriticalTrader
Member
 
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
Default

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?
CriticalTrader is offline  
Reply With Quote
Old 06-24-2012, 04:16 PM   #4
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-24-2012, 05:10 PM   #5
CriticalTrader
Member
 
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
Default

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
(CurrentBar == 1 && i < Times[2].Count && Time[0] == Times[2][i])
{
Print("OnBarUpdate LOOP: Times[2]["+i+"] =" + Times[2][i] + " Closes[2]["+i+"] = "+Closes[2][i]+ " Volumes[2]["+i+"] = "+Volumes[2][i]);
i++;
Print ("OnBarUpdate LOOP: i = "+i);
}
}

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
CriticalTrader is offline  
Reply With Quote
Old 06-25-2012, 07:41 AM   #6
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-25-2012, 08:26 AM   #7
CriticalTrader
Member
 
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
Default

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?
CriticalTrader is offline  
Reply With Quote
Old 06-25-2012, 08:30 AM   #8
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 06-25-2012, 08:59 AM   #9
CriticalTrader
Member
 
Join Date: Jul 2011
Posts: 37
Thanks: 0
Thanked 4 times in 3 posts
Default

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.
CriticalTrader is offline  
Reply With Quote
Old 06-25-2012, 09:04 AM   #10
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

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.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 07-19-2012, 10:37 AM   #11
rcsingleton
Senior Member
 
Join Date: Jan 2008
Posts: 127
Thanks: 8
Thanked 1 time in 1 post
Send a message via Skype™ to rcsingleton
Question Display the Last Price

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?
rcsingleton is offline  
Reply With Quote
Old 07-19-2012, 10:41 AM   #12
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,421
Thanks: 252
Thanked 982 times in 964 posts
Default

rcsingleton, that would be simply Close[0] with CalculateOnBarClose set to false for your indicator / script.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-19-2012, 10:53 AM   #13
rcsingleton
Senior Member
 
Join Date: Jan 2008
Posts: 127
Thanks: 8
Thanked 1 time in 1 post
Send a message via Skype™ to rcsingleton
Default

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.
rcsingleton is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 10:21 PM.