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

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.
    Represents a strongly typed list of objects that can be accessed by index. Provides methods to search, sort, and manipulate lists.


    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 Perr0Grande, Today, 08:16 PM
          0 responses
          2 views
          0 likes
          Last Post Perr0Grande  
          Started by elderan, Today, 08:03 PM
          0 responses
          5 views
          0 likes
          Last Post elderan
          by elderan
           
          Started by algospoke, Today, 06:40 PM
          0 responses
          10 views
          0 likes
          Last Post algospoke  
          Started by maybeimnotrader, Today, 05:46 PM
          0 responses
          11 views
          0 likes
          Last Post maybeimnotrader  
          Started by quantismo, Today, 05:13 PM
          0 responses
          7 views
          0 likes
          Last Post quantismo  
          Working...
          X