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

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.
    Perform fast lookups with string keys. Add elements to Dictionary from System.Collections.Generic.


    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.
        Perform fast lookups with string keys. Add elements to Dictionary from System.Collections.Generic.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by maybeimnotrader, Today, 05:46 PM
        0 responses
        6 views
        0 likes
        Last Post maybeimnotrader  
        Started by quantismo, Today, 05:13 PM
        0 responses
        6 views
        0 likes
        Last Post quantismo  
        Started by AttiM, 02-14-2024, 05:20 PM
        8 responses
        166 views
        0 likes
        Last Post jeronymite  
        Started by cre8able, Today, 04:22 PM
        0 responses
        8 views
        0 likes
        Last Post cre8able  
        Started by RichStudent, Today, 04:21 PM
        0 responses
        5 views
        0 likes
        Last Post RichStudent  
        Working...
        X