![]() |
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 |
|
Junior Member
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
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 ? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Please check log tab of control center for any error messages. Let us know what you find out.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
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 ? |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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.
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 02-02-2011 at 02:47 PM.
|
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
"all series must be hard coded"
OK
Last edited by fredp; 02-02-2011 at 03:03 PM.
|
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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
Ryan M
NinjaTrader Customer Service
Last edited by NinjaTrader_RyanM; 02-02-2011 at 03:02 PM.
|
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Dec 2010
Posts: 8
Thanks: 0
Thanked 0 times in 0 posts
|
"all series must be hard coded"
OK, so I cannot really do what I want thank you |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |