NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 12-01-2008, 03:53 PM   #1
xewoox
Senior Member
 
Join Date: Dec 2008
Posts: 118
Thanks: 0
Thanked 0 times in 0 posts
Default How to copy DataSeries to another DataSeries

I like to find the HighestBar starting from High[1] to High[20].
Do I have to copy 'High' DataSeries elements (1 to 20) to another DataSeries, then pass the new DataSeries into HighestBar () function.
How do I do it?
xewoox is offline  
Reply With Quote
Old 12-01-2008, 04:18 PM   #2
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

That is correct. Or you can just save the value out from the previous bar. In your previous bar just save a variable that does not get reset for when you access HighestBar().
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2008, 04:23 PM   #3
xewoox
Senior Member
 
Join Date: Dec 2008
Posts: 118
Thanks: 0
Thanked 0 times in 0 posts
Default

How do you copy from DataSeries? Would you be able to show the code?
xewoox is offline  
Reply With Quote
Old 12-01-2008, 04:26 PM   #4
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

http://www.ninjatrader-support.com/H...iesObject.html

myDataSeries.Set(High[1]);
int value = HighestBar(myDataSeries, 20);
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-01-2008, 05:52 PM   #5
xewoox
Senior Member
 
Join Date: Dec 2008
Posts: 118
Thanks: 0
Thanked 0 times in 0 posts
Default

myDataSeries.Set(High[1]);

Does this automatic copy High[1], High[2], High[3], High[4], High[5], ... High[19], High[20] into myDataSeries?

I don't really understand how DataSeries works? Would you try to explain further?
xewoox is offline  
Reply With Quote
Old 12-01-2008, 06:42 PM   #6
xewoox
Senior Member
 
Join Date: Dec 2008
Posts: 118
Thanks: 0
Thanked 0 times in 0 posts
Default Need a little explain

I think I got how it works because we try to put the value of the previous bar into the dataseries hence it is always one bar behind the current high.

And I would need to protect the series by

if (CurrentBar < 2)
return;

inside the OnBarUpdate().


This is neat. But would it be possible to have an optional parameter int HighestBar () or functions that uses dataSeries to specify the starting index that would be good too.

Thanks Josh
xewoox is offline  
Reply With Quote
Old 12-02-2008, 07:06 AM   #7
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

You are correct. High[1] always returns the high value of one bar to the left of the current bar.

if(CurrentBar < 2) return; could be:
if(CurrentBar < 1) return;

Because all you need is one bar of history. If there are no bars to the left of the current bar yet, then do nothing.

I do not understand your last statement regarding HighestBar(). HighestBar() returns the index value of the highest bar within a range:
http://www.ninjatrader-support.com/H...ighestBar.html
NinjaTrader_Ben is offline  
Reply With Quote
Old 12-02-2008, 07:21 AM   #8
xewoox
Senior Member
 
Join Date: Dec 2008
Posts: 118
Thanks: 0
Thanked 0 times in 0 posts
Default

I mean add an optional parameter to HighestBar. Instead of

HighestBar (IDataSeries ds, int length),

we can have

HighestBar (IDataSeries ds, int length, int startIndex),

where startIndex is 0 by default
xewoox is offline  
Reply With Quote
Old 12-02-2008, 07:53 AM   #9
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

Thank you for your suggestion, I will send it to development for consideration.

You may want to use MAX(High, 20)[1] or something like that to return the highest VALUE. However, this does not return the bar INDEX with the highest value. This link will help:
http://www.ninjatrader-support.com/H...aximumMAX.html
NinjaTrader_Ben 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.Reset() snaphook General Programming 16 11-11-2009 10:43 AM
DataSeries Weirdness CashCache General Programming 1 09-04-2008 10:53 PM
DataSeries Issue Antonio79 General Programming 8 09-03-2008 12:40 PM
OHLC Dataseries? michaelbb Indicator Development 3 05-28-2008 09:45 AM
DataSeries doubt cls71 Indicator Development 1 01-21-2008 10:49 PM


All times are GMT -6. The time now is 07:10 AM.