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 10-19-2009, 02:01 PM   #1
blarouche
Senior Member
 
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default Exposing a dictionary

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
blarouche is offline  
Reply With Quote
Old 10-19-2009, 02:12 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

Can you try some try-catch blocks to try and isolate the area of problem? Unfortunately Dictionary use is beyond my scope.
NinjaTrader_Josh is offline  
Reply With Quote
Old 10-20-2009, 01:49 AM   #3
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 10-20-2009, 07:14 AM   #4
blarouche
Senior Member
 
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

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
blarouche is offline  
Reply With Quote
Old 10-20-2009, 08:16 AM   #5
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Quote:
Originally Posted by blarouche View Post
I am just woundering why it is so easy to expose a variable or a DataSeries and so complicated with a list ?
It is as easy as with a simple variable, at least in my own code. I still do not understand what you are are doing. If you pass over an empty dictionary with the property, then you will get an empty dictionary?

Regards
Ralph
Ralph is offline  
Reply With Quote
Old 10-20-2009, 08:27 AM   #6
blarouche
Senior Member
 
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

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
blarouche is offline  
Reply With Quote
Old 10-20-2009, 08:49 AM   #7
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

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
Ralph is offline  
Reply With Quote
Old 10-20-2009, 09:42 AM   #8
blarouche
Senior Member
 
Join Date: Apr 2009
Posts: 198
Thanks: 0
Thanked 0 times in 0 posts
Default

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
blarouche is offline  
Reply With Quote
Old 10-20-2009, 10:25 AM   #9
Ralph
Senior Member
 
Join Date: Jul 2008
Posts: 527
Thanks: 0
Thanked 9 times in 6 posts
Default

Only an example installation would help me to understand the context.

Regards
Ralph
Ralph 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
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


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