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

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:
          [LEFT][COLOR=#252C2F][FONT=Courier]for(int i = 0; i < Values.Count(); i++)
          {
                 double value = Values[i][0];
          }[/FONT][/COLOR][/LEFT]
          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 Kaledus, Today, 01:29 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post Kaledus
                  by Kaledus
                   
                  Started by PaulMohn, Today, 12:36 PM
                  1 response
                  16 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by yertle, Yesterday, 08:38 AM
                  8 responses
                  36 views
                  0 likes
                  Last Post ryjoga
                  by ryjoga
                   
                  Started by rdtdale, Today, 01:02 PM
                  1 response
                  6 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by alifarahani, Today, 09:40 AM
                  3 responses
                  18 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Working...
                  X