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 02-02-2011, 12:57 PM   #1
fredp
Junior Member
 
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default indicator based on 2 instruments

Hello,
I want to draw an indicator which applies on a chart with 2 instruments and which uses both instruments prices. In the OnBarUpdate() method, Close(0) refers to the main instrument. What is the object path to acess the 2nd instrument's equivalent " Close(0)" from that method?
thank you
fredp is offline  
Reply With Quote
Old 02-02-2011, 01:06 PM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hello fredp,

The secondary series close price can be accessed with Closes[1][0]

Documentation for multiple series scripts is available here:
http://www.ninjatrader.com/support/h...nstruments.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-02-2011, 01:50 PM   #3
fredp
Junior Member
 
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you for your quick answer but I've got a problem. Maybe because i's not multitime frame instruments, but 2 stocks in the same timeframe.
I made 3 little tests on a chart with 2 stocks in the same panel and same timeframe, "line on close".
1st test:
Plot0.Set(Closes[0][0]);
=>it's OK (1st stock duplicated )
2nd test:
Plot0.Set(Closes[0][0]-Closes[0][0]);
=>it's OK (dummy indicator flat to 0)
3rd test:
Plot0.Set(Closes[0][0]-Closes[1][0]);
=>(after recompile and reload script) Nothing at all, indicator's line disapears

just as if Closes[1] was not initialized with the array of the 2nd stock prices.
did I miss something ?
fredp is offline  
Reply With Quote
Old 02-02-2011, 02:07 PM   #4
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Please check log tab of control center for any error messages. Let us know what you find out.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-02-2011, 02:25 PM   #5
fredp
Junior Member
 
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

Error Message (translated from french as I am on a french computer)/
"Error on calling "OnBarUpdate" method for indicator 'diff' on bar 0 : index is out of the limits of the array"
It seems that the second column of the matrix Closes is not automatically initialized with the 2nd instrument of the context. I thought it was.
I have read the example of overriding "initialize" but it is to create another time frame with the same instrument or a 2nd "hard-coded" instrument. My aim is to take into account dynamically the second instrument of the chart. Is it possible ?
fredp is offline  
Reply With Quote
Old 02-02-2011, 02:35 PM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

That message comes up when attempting to access bar objects that don't exist. Help for this issue is available here:
http://www.ninjatrader-support.com/v...ead.php?t=3170

All series must be hard coded in. Unfortunately there's no way to read it from other series that are applied to the chart.

If you're still having trouble getting the indicator to plot:
Please share the complete script, making sure to include the Initialize method. You can copy-paste into this thread or share the .cs file from:
My Documents\NinjaTrader\bin\custom\indicator

Let us know your data provider, the instrument and interval you have it applied to and we can give it a run here.
Last edited by NinjaTrader_RyanM; 02-02-2011 at 02:47 PM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-02-2011, 02:50 PM   #7
fredp
Junior Member
 
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

"all series must be hard coded"
OK
Last edited by fredp; 02-02-2011 at 03:03 PM.
fredp is offline  
Reply With Quote
Old 02-02-2011, 02:57 PM   #8
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Yes, you're on the right track. You have no series added to the Initialize method and Ninja won't automatically add this. I would take a look at the sample multiInstrument strategy for an example implementation. Click Tools > Edit NinjaScript > Strategy > SampleMultiInstrument
Documentation for this is here:
http://www.ninjatrader.com/support/h...nstruments.htm
Last edited by NinjaTrader_RyanM; 02-02-2011 at 03:02 PM.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 02-02-2011, 03:05 PM   #9
fredp
Junior Member
 
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
Default

"all series must be hard coded"
OK, so I cannot really do what I want
thank you
fredp 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
How to add an indicator based on time-based bars to a tick chart? aviat72 Version 7 Beta General Questions & Bug Reports 1 07-27-2010 04:10 PM
how to write an indicator based on KAMA goukotegawa Indicator Development 0 02-28-2010 11:27 AM
indicator based on different instruments gamevoodoo General Programming 1 08-20-2009 06:42 AM
Close Mulliple instruments based on profit Jeff 15 ATM Strategies (Discretionary Trading) 1 06-02-2008 10:08 AM
Strategy based on indicator value, not price? cassb Strategy Analyzer 2 12-19-2007 06:44 AM


All times are GMT -6. The time now is 01:48 PM.