• 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

Create variable in private void ()

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

    Create variable in private void ()

    Hello,

    I've got this:

    PHP Code:
        for (int x 1;   x++)
                { 
                    
    DoStuff(x);
                } 
    Where x is barsinprogress (I added two symbols: SPY, DIA).
    PHP Code:
            private void DoStuff(int x )

        
    //in here i got two integers a, b;
      

    Now when the first symbol (loop x=1) is done, it has stored something in integer a and b.
    Now the second symbol is on, DIA, but now it will overwrite something what is stored in a by SPY.

    How can I overcome this? So that SPY and DIA have is own 'a' and 'b'. (I think, it should be in the loop i.e. It creats a1, b1, a2, b2 as integers/doubles, but how do I do that?)

    Someone who has a suggestion for me?

    Thanks

    #2
    Hello no111,
    You can create a List of your variable and store the values there.
    http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

    Unfortunately its more of C# query and beyond what we could support.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Originally posted by no111 View Post
      Hello,

      I've got this:

      PHP Code:
          for (int x 1;   x++)
                  { 
                      
      DoStuff(x);
                  } 
      Where x is barsinprogress (I added two symbols: SPY, DIA).
      PHP Code:
              private void DoStuff(int x )

          
      //in here i got two integers a, b;
       

      Now when the first symbol (loop x=1) is done, it has stored something in integer a and b.
      Now the second symbol is on, DIA, but now it will overwrite something what is stored in a by SPY.

      How can I overcome this? So that SPY and DIA have is own 'a' and 'b'. (I think, it should be in the loop i.e. It creats a1, b1, a2, b2 as integers/doubles, but how do I do that?)

      Someone who has a suggestion for me?

      Thanks
      Easiest way is to have 2 more integers, so that each set is separate and populated depending on the value of x.

      private void DoStuff(int x )
      {
      if (x == 1) {//populate a1 and b1}
      else if (x == 2) {//populate a2 and b2}
      }

      Comment


        #4
        Originally posted by koganam View Post
        Easiest way is to have 2 more integers, so that each set is separate and populated depending on the value of x.

        private void DoStuff(int x )
        {
        if (x == 1) {//populate a1 and b1}
        else if (x == 2) {//populate a2 and b2}
        }
        Thank you for an answer. My idea was to add more than 2 symbols, for example 10 ETF's so I can measure the performance of the strategy better (with combined results if you backtest a basket, you don't get a equity curve for example).

        Any ideas for that?

        Comment


          #5
          Originally posted by no111 View Post
          Thank you for an answer. My idea was to add more than 2 symbols, for example 10 ETF's so I can measure the performance of the strategy better (with combined results if you backtest a basket, you don't get a equity curve for example).

          Any ideas for that?
          You can use a bunch of suitably named variables or you can use Arrays to hold the two sets of values.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by thgamey, Today, 08:38 PM
          0 responses
          2 views
          0 likes
          Last Post thgamey
          by thgamey
           
          Started by johnnybegoode, Today, 07:02 PM
          0 responses
          4 views
          0 likes
          Last Post johnnybegoode  
          Started by YevhenShynkarenko, Today, 05:02 PM
          1 response
          11 views
          0 likes
          Last Post YevhenShynkarenko  
          Started by lahabatha, Today, 04:42 PM
          0 responses
          12 views
          0 likes
          Last Post lahabatha  
          Started by explorer101, Today, 03:39 PM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Working...
          X