• 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

nested for loop of a barIndex

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

    #61
    Hello frankduc,

    In your second sample you would need to use the indicators values collection from within the loop as well, just like you did with the Count. You are using the parent indicators "Values" collection from within the loop and have not used the RMMA's Values collection. Replace "Values" in the loop with your indicator syntax and its Values collection.

    Please let me know if I may be of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #62
      Ok but i still get a bunch of zero's:

      Code:
      for(int i = 0; i < RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values.Count(); i++)
          {
                  double value = RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values[i];
      
                 Print(value);
              }

      Comment


        #63
        Hello frankduc,

        What you provided will not compile, are you certain that you compiled successfully before re testing?

        You are now trying to print the series<double> directly instead of using a BarsAgo and getting a value from that series. In what I provided previously that shows how to also use a BarsAgo with a Values collection. You would need to form the syntax to use a BarsAgo to get the value you wanted.




        Please let me know if I may be of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #64
          Jesse,

          First, this is working. It returns all values in RMMA if i print.

          Code:
          for(int i = 0; i < RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values.Count(); i++)
                  {
                      double value = RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values[i][0];
          
                   Print(value);
                    }

          This is what you provided, but i dont see how it relates to barsago. I dont understand what you mean by using barago. Its not different from using select or a foreach?

          Code:
          for(int i = 0; i < Values.Count(); i++) { double value = Values[i][0]; }
          If i try to Print(value); outside of the brackets i get nothing even if i call a variable

          Code:
          private double value = 0;
          So nothing happen in my if statement: it return nothing and i dont understand why.

          Code:
          if(value < highPrice && value > lowPrice)
          TY

          Frank

          Comment


            #65
            Jesse,

            Edit update:

            I forgot to remove the local variable double value.

            Now the variable value is working in the if statement but it only returns one value not all of them (15 values). Obviously the last one in the list of the OW.

            Can i move the for loop of the RMMA from OBU to OR? Wont work? Its always the same issue outside or inside the bracket and you get a different result.

            Frank
            ty



            Comment


              #66
              Hello frankduc,

              This is what you provided, but i dont see how it relates to barsago. I dont understand what you mean by using barago. Its not different from using select or a foreach?
              In the select statement you are specifically selecting one value, what I had provided is the normal way to access a series which includes the BarsAgo. I suggested this because this relates to the normal ways to access data or how you would access data in all other areas of OnBarUpdate. If you wnat to use Linq and C# methods you can but that would be something you need to learn about/execute yourself.

              BarsAgo and Series are NinjaScript concepts you can read about in the help guide. If you are having difficulty understanding how to use the series from the indicator, I would suggest to research the help guide further or do more simple tests to better understand the syntax/framework you are using.

              If i try to Print(value); outside of the brackets i get nothing even if i call a variable

              So nothing happen in my if statement: it return nothing and i dont understand why.
              It seems there is still some confusion surrounding the core C# concepts used here such as loops and scope. I am not able to walk through using the loop/if statements again at this point as this is a C# language feature. I would suggest to either use C# tutorials to gain a firm understanding of C# syntax before you continue or to outsource this work to a NinjaScript developer.


              Can i move the for loop of the RMMA from OBU to OR? Wont work? Its always the same issue outside or inside the bracket and you get a different result.
              OnRender and OnBarUpdate are for different purposes. I know you have tried this in our past conversations, I would not suggest trying to do that. If you are able to execute your goal from OnBarUpdate successfully you could look at using OnRender if required, however OnRender is just for rendering we do not suggest using that for calculation logic.

              Please let me know if I may be of further assistance.

              JesseNinjaTrader Customer Service

              Comment


                #67
                Hello Jesse,

                I did what you were suggesting and move everything to OnBarUpdate.

                So now you can say that every values of the RMMA are applied to the if statement.

                Code:
                for(int i = 0; i < RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values.Count(); i++)
                        {
                            value = RMMA(MultiMA1types.VWMA, 2, 160, 10, 2, 128, 0.75, 0.5).Values[i][0];
                
                                   
                
                      if(value < highPrice && value > lowPrice)
                       {
                But i am disappointed, Printing(value) after the if statement does show that every value are processed in the if statement and i even check in my formulas and its working.

                Like i said at the end there is a list that gather all result from the formulas and a lambda is choosing the closest value from my variable close[0].

                The variable nearclose at the very end of the bottom line should of produce 15 returns instead of only one since there is 15 values tested in the if statement.

                Is there a way that the 15 values tested in the if statement be tested one by one and not as a group of values?


                Frank

                Comment


                  #68
                  Hello frankduc,

                  But i am disappointed, Printing(value) after the if statement does show that every value are processed in the if statement and i even check in my formulas and its working.

                  Like i said at the end there is a list that gather all result from the formulas and a lambda is choosing the closest value from my variable close[0].
                  From what is provided I can't see what you are printing to understand this statement. If you are mentioning a problem here you would likely need to continue to debug the situation using prints and/or use C# learning resources related to what you are doing to explore that further.



                  The variable nearclose at the very end of the bottom line should of produce 15 returns instead of only one since there is 15 values tested in the if statement.

                  Is there a way that the 15 values tested in the if statement be tested one by one and not as a group of values?
                  It does not appear you included this syntax in your sample, I am not able to see any variables named "nearclose" shown. As such I would not be able to provide any detail there without the full context. Because your questions relate to using if statements and also seems to include a loop I could suggest to use C# educational resources to gather more information about the syntax you are using and how it can be used. Alternatively I can also suggest to outsource this work to a third party developer to expedite the development process.


                  Please let me know if I may be of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kweiss, Today, 08:35 PM
                  0 responses
                  2 views
                  0 likes
                  Last Post kweiss
                  by kweiss
                   
                  Started by zulok, Today, 05:02 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post zulok
                  by zulok
                   
                  Started by Andreas M., Today, 04:42 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post Andreas M.  
                  Started by sidlercom80, Today, 12:29 PM
                  2 responses
                  24 views
                  0 likes
                  Last Post fx.practic  
                  Started by itrader46, Today, 02:49 PM
                  3 responses
                  17 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Working...
                  X