Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Exposing a dictionary

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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

    #2
    Can you try some try-catch blocks to try and isolate the area of problem? Unfortunately Dictionary use is beyond my scope.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      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

      Comment


        #4
        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

        Comment


          #5
          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

          Comment


            #6
            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

            Comment


              #7
              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

              Comment


                #8
                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

                Comment


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

                  Regards
                  Ralph

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by tkaboris, Today, 08:01 AM
                  1 response
                  7 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by Lumbeezl, 01-11-2022, 06:50 PM
                  31 responses
                  817 views
                  1 like
                  Last Post NinjaTrader_Adrian  
                  Started by xiinteractive, 04-09-2024, 08:08 AM
                  5 responses
                  15 views
                  0 likes
                  Last Post NinjaTrader_Erick  
                  Started by swestendorf, Today, 11:14 AM
                  2 responses
                  6 views
                  0 likes
                  Last Post NinjaTrader_Kimberly  
                  Started by Mupulen, Today, 11:26 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post Mupulen
                  by Mupulen
                   
                  Working...
                  X