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

Dictionary

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

    #16
    Originally posted by koganam View Post

    You use brackets, not braces, when you declare and initialize a struct.

    Like so:
    Code:
    StockEntry ("ABC", PeriodType.Minute, 1, 0)
    The keyword new is not mandatory.
    Thanks for writing that all out. So I'm not needing List any longer?...
    List<StockEntry> _stocks = new List<StockEntry>();
    or any kind of Add?...
    _stocks.Add(StockEntry("ABC", PeriodType.Minute, 5, 0));


    I tried using just this...
    StockEntry("ABC", PeriodType.Minute, 5, 0);
    But got the error "StockEntry is a 'type' but used like a 'variable' "
    So I looked at your reference and this below seemed to work, should I use this?...
    StockEntry stockentry1 = new StockEntry("ABC", PeriodType.Minute, 5, 0);
    Last edited by zachj; 09-22-2013, 08:17 PM.

    Comment


      #17
      Originally posted by zachj View Post
      Thanks for writing that all out. So I'm not needing List any longer?...
      List<StockEntry> _stocks = new List<StockEntry>();
      or any kind of Add?...
      _stocks.Add(StockEntry("ABC", PeriodType.Minute, 5, 0));


      I tried using just this...
      StockEntry("ABC", PeriodType.Minute, 5, 0);
      But got the error "StockEntry is a 'type' but used like a 'variable' "
      So I looked at your reference and this below seemed to work, should I use this?...
      StockEntry stockentry1 = new StockEntry("ABC", PeriodType.Minute, 5, 0);
      StockEntry("ABC", PeriodType.Minute, 5, 0); is an expression, not a statement, so should not be on a line by itself: you use it as an assignment subject.

      StockEntry stockentry1 = new StockEntry("ABC", PeriodType.Minute, 5, 0); is a statement, and a valid one to assign and name a specific StockEntry struct.

      Whether you want to put the structs in a list really depends on what you want to do. I simply gave you the statements/expressions that give you the ability to create the necessary objects. I did suggest that you may want to use a list of structs. I simply showed you how to create the structs that you might want to track.

      You can name the structs before you store them, or you can store them directly, and name and assign them when you are ready to use them, after accessing them by their index in the List<>. The struct is simply an object that has, in one place, all the properties that you want to track.

      Comment


        #18
        Originally posted by koganam View Post
        StockEntry("ABC", PeriodType.Minute, 5, 0); is an expression, not a statement, so should not be on a line by itself: you use it as an assignment subject.

        StockEntry stockentry1 = new StockEntry("ABC", PeriodType.Minute, 5, 0); is a statement, and a valid one to assign and name a specific StockEntry struct.

        Whether you want to put the structs in a list really depends on what you want to do. I simply gave you the statements/expressions that give you the ability to create the necessary objects. I did suggest that you may want to use a list of structs. I simply showed you how to create the structs that you might want to track.

        You can name the structs before you store them, or you can store them directly, and name and assign them when you are ready to use them, after accessing them by their index in the List<>. The struct is simply an object that has, in one place, all the properties that you want to track.
        I think that I need to use a List. What I'm trying to do is just be able to Count & track the # of times each stock has Entered Long in a multi-instrument scipt and ultimately keep 10minutes between trades per individual instrument. So if there's been more than 1 trade it will then go to BarsSinceEntry() to make sure two 5min bars have elapsed before it can enter another trade.

        The only way I can have an error NOT pop up is by adding to the list in this way below. Does this look acceptable?...
        List<StockEntry> _stocks = new List<StockEntry>();
        protected override void Initialize()
        {
        _stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
        //other stock added here..
        }

        Comment


          #19
          Originally posted by zachj View Post
          I think that I need to use a List. What I'm trying to do is just be able to Count & track the # of times each stock has Entered Long in a multi-instrument scipt and ultimately keep 10minutes between trades per individual instrument. So if there's been more than 1 trade it will then go to BarsSinceEntry() to make sure two 5min bars have elapsed before it can enter another trade.

          The only way I can have an error NOT pop up is by adding to the list in this way below. Does this look acceptable?...
          List<StockEntry> _stocks = new List<StockEntry>();
          protected override void Initialize()
          {
          _stocks.Add(new StockEntry { Name = "ABC", Period = PeriodType.Minute, Value = 5, Count = 0 } );
          //other stock added here..
          }
          Certainly valid syntax.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by TradeForge, Today, 02:09 AM
          0 responses
          2 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          2 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by elirion, Today, 01:36 AM
          0 responses
          4 views
          0 likes
          Last Post elirion
          by elirion
           
          Started by gentlebenthebear, Today, 01:30 AM
          0 responses
          4 views
          0 likes
          Last Post gentlebenthebear  
          Started by samish18, Yesterday, 08:31 AM
          2 responses
          9 views
          0 likes
          Last Post elirion
          by elirion
           
          Working...
          X