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 ttodua; 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.


    As well as a publicly available link to an educational site.


    You would also want to call Update() in the get for the public variable.if you are not already doing this.
    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.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, 04-16-2026, 01:02 PM
        0 responses
        37 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        23 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        162 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        98 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        152 views
        2 likes
        Last Post CaptainJack  
        Working...
        X