![]() |
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 |
|
Senior Member
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
OK guys
I am fed up with something I've tried to code and it doesn't work. I definitively need help on that... I have a dictionary in an indicator that I want to expose to another indicator. I keep on getting the following error : Object reference not set to an instance of an object... In my first indicator I initialize the dictionary in the variables section private Dictionary<string,List<double>> sup = new Dictionary<string,List<double>>(); In my property I have the following : [Browsable(false)] [XmlIgnore()] public Dictionary<string,List<double>> Sup { get { Update(); return sup; } } In the second indicator I am trying to get the list of my dictionary like that : if(MyIndicator().Sup.Count != 0){ foreach(KeyValuePair<string, List<double>> key in MyIndicator().Sup){ List<double> thislist = key.Value as List<double>; foreach(double item in thislist) Print(Time[0]+" Mylist item : "+item); } } What am I doing wrong ? Thanks Bernard |
|
|
|
|
|
#2 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Can you try some try-catch blocks to try and isolate the area of problem? Unfortunately Dictionary use is beyond my scope.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Hi Bernard,
you could place a print statement after each code line. This way you find out quickly where the exeption is thrown. Both, dictionaries and lists, accept null-values. Make sure that does not happen or test for null-values before usage. Regards Ralph |
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
Ralph
That's exactly what I did. I checked for the null conditions , now I don't get an error anymore but it returns nothing. From my other indicator I use a print statement to verify the List Count and it returns 0. I am just woundering why it is so easy to expose a variable or a DataSeries and so complicated with a list ? I can't use the Update() method in the get method anymore... Bernard |
|
|
|
|
|
#5 | |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Quote:
Regards Ralph |
|
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
The way my code works is that I have many dictionaries of <int,List<double> that contains Support and resistance levels calculated in one indicator.
The dictionaries get filled at the open of the market ( firstTick of Bar on a 30 minutes Chart CalculateonClose : false). I need these dictionaries to draw levels on another Chart ( a 1 Minute Chart) In have created a property in my indicator so that I can send these dictionaries to the indicator that will draw S/R Lines. In the tests I did, I found out that the dictionaries contains the data and they are good but it seems it doesn't get to the property ! Bernard |
|
|
|
|
|
#7 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
If you put a print statement in the property getter:
public Dictionary<string,List<double>> Sup { get { Update(); Print(sup.Count); return sup; } } and another one into your other indicator: Print(Sup.Count); Do you see the same numbers? Regards Ralph |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
|
Ralph
Thank you for trying to get my problem resolved. I did what you told me to do here is the result : Error on calling 'OnBarUpdate' method for indicator 'Indicator1' on bar 1 : Object reference not set to an instance od an object. 0 0 0 0 0 0 0 0 0 0 But if I print the dictionary from my indicator1 code I get the lists OK Bernard |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
|
Only an example installation would help me to understand the context.
Regards Ralph |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Exposing a Variable for use in a strategy | daven | Strategy Development | 2 | 08-20-2009 09:59 PM |
| Nasty bug trying to add() to a Dictionary... | funk101 | General Programming | 2 | 04-18-2009 10:46 PM |
| Exposing a Color parameter? | higler | General Programming | 1 | 05-13-2008 06:21 AM |
| Exposing non dataseries variable | tquinn | General Programming | 10 | 05-17-2007 04:12 PM |
| Exposing a non DataSeries property in an indicator | tquinn | Indicator Development | 4 | 01-11-2007 02:29 PM |