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


    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 < 3 ; 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 Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          580 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          335 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          102 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          554 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          552 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X