• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

initialize DataSeries(this) into KeyValue pair (i.e. dictionary)

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

    initialize DataSeries(this) into KeyValue pair (i.e. dictionary)

    question 1:

    in Initialize I had direct BoolSeries:
    Code:
    my = new BoolSeries(this);
    (p.s. please, dont tell me to use this as a solution! I dont need that.)

    however, i wanted to change it to Dictionary. However, when I use this :

    Code:
    initialize()          {   my = new Dictionary<string, BoolSeries>();  }
    OnBarUpdate() {   my["is_ma_crossover"][0] = ......                   }
    I get error right away after adding on chart : "The given key was not present in the dictionary."
    when i try without "series", then everything works well:

    Code:
    initialize()          {   my = new Dictionary<string, bool>();  }
    OnBarUpdate() {   my["is_ma_crossover"] = ......                   }
    however, i dont want that. I need to use BoolSeries in Dictionary, which i can refer with index, like:
    Code:
     if(my["is_ma_crossover"][3])  {.....}

    question 2
    I know than NT7 uses net 3.5 version. however, which C# (maybe it is called compiler) version it used? 2.0 or 4.0 or 6.0 or which one?
    Last edited by TazoTodua; 09-24-2017, 10:20 AM.

    #2
    Hello TazoTodua,

    This would fall under general C# and is not specific to NinjaScript.

    When adding an item to a Dictionary you would need to use the .Add() method.

    Below is a publicly available link to the Microsoft C# documentation on Dictionary.
    https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    As well as a publicly available link to an educational site.
    https://www.dotnetperls.com/dictionary

    You would also want to call Update() in the get for the public variable.if you are not already doing this.
    https://ninjatrader.com/support/help...nt7/update.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      thanks.
      1) so, i have to initialize like this?:
      my.Add("is_ma_crossover", BoolSeries(this) );

      (because i cant understand how to pass "this" ...


      2) please, i had question 2 too, could you answer that too?

      Comment


        #4
        Hello TazoTodua,

        It was my understanding you did not want to use a BoolSeries and instead wanted to use a Dictionary object. Is this not the case?

        If you want to use a Dictionary you would not have that line of code. Instead you would declare a Dictionary and initialize this in Initialized().

        private Dictionary<string, bool> myDictionary;

        myDictionary = new Dictionary<string, bool>;

        myDictionary.Add("element1Key", false);

        Below is a link to an educational site that includes an example of how to use a Dictionary.
        https://www.dotnetperls.com/dictionary
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by pecunianonolet, 11-28-2016, 03:34 AM
        4 responses
        3,135 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by contrax, Today, 08:20 AM
        2 responses
        12 views
        0 likes
        Last Post contrax
        by contrax
         
        Started by brownsfan019, Today, 07:54 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_ChristopherJ  
        Started by Amitabha, Today, 04:50 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by JulieG, Today, 12:40 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_ChrisSch  
        Working...
        X