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

return more than one answer Print()

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

    return more than one answer Print()

    Hello,



    index0 return more than one answer for ex (bar 1700, 1750, 1758) . unfortunately if i
    sumOfVolumes10 of all the index0 it only returns the last answer index in index0 (1758). Is there a way i can make it return the volume of each value in index0?

    Thank you
    Last edited by frankduc; 08-07-2019, 09:55 AM.

    #2
    Hello frankduc,

    Use an array or list.

    Below are publicly available links to educational sites on c#.
    Create and loop over a string array. Access array Length and get elements at indexes.

    Create a new List, add elements to it, and loop over its elements with for and foreach.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I tried that but you cant use a for loop in a list?

      for (int barIndex = index; barIndex <= ChartBars.ToIndex; barIndex++)
      {
      sumOfVolumes10 += Bars.GetVolume(barIndex);


      if(cma < Bars.GetHigh(barIndex) && cma > Bars.GetLow(barIndex))
      {
      index0 = barIndex;

      List<int> Minlist = new List<int>() {index0};

      for(int y = 0; y < Minlist.Count; y++)
      {
      Minlist0 = Minlist[y];




      Print(Minlist0);


      }

      }
      }

      Comment


        #4
        Hello frankduc,

        Yes, you can loop over a list with a for loop.

        In the educational site DoNetPerls on list scroll to the heading For-Loop.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          But its not applying the for loop to every value it just cumulate the volume from index to the last value in Minlist.


          for (int barIndex = index; barIndex <= ChartBars.ToIndex; barIndex++)
          {



          if(cma < Bars.GetHigh(barIndex) && cma > Bars.GetLow(barIndex))
          {
          index0 = barIndex;

          List<int> Minlist = new List<int>() {index0};

          for(int y = 0; y < Minlist.Count; y++)
          {
          Minlist0 = Minlist[y];

          for (int AIndex = index; AIndex <= Minlist0; AIndex++)

          {
          sumOfVolumes10 += Bars.GetVolume(AIndex);

          Print(sumOfVolumes10);
          }



          }

          }
          }

          Comment


            #6
            Hello frankduc,

            List<int> Minlist = new List<int>() {index0};

            This is creating a new list and only adding 1 element which is the barIndex value.

            Can you clarify your meaning when you mention: "But its not applying the for loop to every value it just cumulate the volume from index to the last value in Minlist."?

            I am not seeing that any volume is being added to the Minlist list, only the barIndex value.

            When you say it is not apply the loop to every value, are you using prints and seeing that there isn't the same number of prints as the Minlist.Count value?

            What is the Minlist.Count?
            How many prints are you seeing from the loop?
            Last edited by NinjaTrader_ChelseaB; 08-07-2019, 02:15 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              You need to reset sumofvalues10?

              Comment


                #8
                List<int> Minlist = new List<int>() {index0}; returns more than one value. It list all the value that are equal to if(cma < Bars.GetHigh(barIndex) && cma > Bars.GetLow(barIndex))

                That part index0 = barIndex; give me all the values that are equal to cma. cma is an average it return for exemple 2850. The if part return all the values in barIndex position on the chart = to 2850.

                List<int> Minlist = new List<int>() {index0}; is just relisting all the values. ( bar 1020, 1025, 1030 , etc)

                index is a position in bar number in the chart (lowest value in number of bars) for exemple bar 800.

                I want the volume between index (800) and each value returned by if(cma < Bars.GetHigh(barIndex) && cma > Bars.GetLow(barIndex))

                volume from 800 -----> 1020
                800 -----> 1025
                800 -----> 1030

                I dont know how to do that or if its possible. What's bugging me is that i cant apply a for loop to get the volume for each values, its always returning the last value 1030.


                for (int barIndex = index; barIndex <= ChartBars.ToIndex; barIndex++)
                {

                if(cma < Bars.GetHigh(barIndex) && cma > Bars.GetLow(barIndex))
                {
                index0 = barIndex;

                }
                }


                for (int barIndex = index; barIndex <= index0; barIndex++)
                {

                sumOfVolumes10 += Bars.GetVolume(barIndex);
                Print(sumOfVolumes10);
                }

                This only return the volume for 800 to 1030. but not the other 2 values.

                Thank you
                Last edited by frankduc; 08-08-2019, 06:53 AM.

                Comment


                  #9
                  Hello frankduc,

                  A loop will simply transverse over your specified indexes. They will not return anything. You are assigning the same variable in your loop, so you are always updating it. This will always give you the last result.

                  If you are trying to collect a few indexes instead of updating a single variable in your loop. I recommend using a list. This is a general C# concept and documentation for using Lists can be found on Microsoft's publicly available documentation. You may also find educational C# resources external to NinjaTrader that describe using Lists.

                  Lists - https://docs.microsoft.com/en-us/dot...tframework-4.8

                  External educational resource - https://www.c-sharpcorner.com/article/c-sharp-list/

                  The links above are publicly available.
                  JimNinjaTrader Customer Service

                  Comment


                    #10
                    This is how you would get each object in a c# list of objects with a for loop

                    List<object> list = new List<object>();
                    for (int i = 0; i < list.Count; i++)
                    {
                    SomeMethodThatDoesSomethingWithAnObject(list[i]);
                    }
                    List class is a collection and defined in the System.Collections.Generic namespace and it provides the methods and properties like other Collection classes such as add, insert, remove, search etc.
                    Last edited by garylinen; 12-18-2019, 11:22 PM.

                    Comment


                      #11
                      interesting link

                      ty

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by jclose, Today, 09:37 PM
                      0 responses
                      5 views
                      0 likes
                      Last Post jclose
                      by jclose
                       
                      Started by WeyldFalcon, 08-07-2020, 06:13 AM
                      10 responses
                      1,413 views
                      0 likes
                      Last Post Traderontheroad  
                      Started by firefoxforum12, Today, 08:53 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post firefoxforum12  
                      Started by stafe, Today, 08:34 PM
                      0 responses
                      11 views
                      0 likes
                      Last Post stafe
                      by stafe
                       
                      Started by sastrades, 01-31-2024, 10:19 PM
                      11 responses
                      169 views
                      0 likes
                      Last Post NinjaTrader_Manfred  
                      Working...
                      X