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

highest high

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

    highest high

    Hi,

    I try to get the highest high from my index but indicator wont appear in the chart even if it compile. What did i do wrong? Is it because it only work OnBarUpdate, what about Onrender?

    for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex++)
    {
    int highestBarsAgo = HighestBar(High, barIndex);

    double highestPrice = High[highestBarsAgo];

    Print(highestPrice);
    }


    If i use


    double highPrice = Bars.GetHigh(barIndex);

    Print(highPrice);

    It return more than one answer. It start from first bar and give me the high price of that bar and than keep on giving me the high of the next bars. All i want is the highest high of the entire index.




    ty
    Last edited by frankduc; 06-11-2019, 07:04 AM.

    #2
    Hello frankduc,

    Thanks for your post.

    The Bars.GetHigh() will return the high of the bar selected (barIndex). As this is (I assume) inside a for loop, it would be expected to return the high of every bar.
    What you could do is to save the High in a double variable and compare the next bars high in the loop and if higher, save the new high. Repeat until the for loop ends and then place your print statement outside the for loop. Note: prior to the for loop, set the double to MinValue.

    The issue here: HighestBar(High, barIndex); is that barIndex is based on GetBarIdxByX() which returns the specific bar number and the method HighestBar() will use that as the "period" to look for a high.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Paul,

      If i do that, it means i must compare one by one each high bars return. If there's 200 bars that makes 200 high's to compare to each other. If i understand your solution correctly.

      Would be possible to store all the high's in a ListT


      double highPrice = Bars.GetHigh(barIndex);

      List<double> Hlist = new List<double>() {highPrice};

      for(int h = 0; h < Hlist.Count; h++)
      {
      Hlist[h] = (Hlist[h]);

      double[] numbers=new double[]{Hlist[h]};
      double maximumNumber=numbers.Max();

      Print(maximumNumber);
      }
      One problem its not working it returns all numbers and not just the highest
      Last edited by frankduc; 06-11-2019, 09:05 AM.

      Comment


        #4
        Hello frankduc,

        Thanks for your reply.

        If you haven't tried what I suggested please do.

        I don't see what you are suggesting as being more efficient and would seem to involve just as much if not more effort.
        Paul H.NinjaTrader Customer Service

        Comment


          #5
          I dont really understand what you are suggesting.
          Do you mean:

          for (double i = 0; i <= barIndex; i++)

          double high = i;


          if(
          High
          [0] <
          High
          [1]) ???


          NT should of simply create a
          Bars.GetHigh that only extract the high of the index instead of every bars. Who needs the high of every bars anyway?

          Comment


            #6
            Hello frankduc,

            Thanks for your reply.

            In your original post, it appears that you are running a for loop based on a begin and end bar as defined by mouse click. In the for loop which is a limited number of bars, as you are processing each bar in the for loop to collect the high of each bar and compare to a previous high starting with a min value. At the end of the for loop processing, you would have the Highest value of the bars that were processed in the for loop.


            Paul H.NinjaTrader Customer Service

            Comment


              #7
              if that is what you meant it ain't returning what's expected.

              double highPrice = Bars.GetHigh(barIndex);
              double high = double.MinValue;
              for (int i = 0; i <= highPrice; i++)

              high = Bars.GetHigh(i);

              Print(high);


              Is it possible to use
              double
              minValue
              =
              chartScale.MinValue; to get the highest and lowest of the index?

              Can we replace charscale by barIndex somehow?
              Last edited by frankduc; 06-11-2019, 11:56 AM.

              Comment


                #8
                Hello frankduc,

                The solution I proposed was intended to fit within your for-loop in terms of getting the High of each bar in the for-loop and comparing the actual High to a double variable (that is initialized to MinValue prior to the for-loop) and if the High is > that the variable, to save the High to the variable so that at the end of the for-loop the variable holds the highest high found and then you print th value outside of the for-loop.



                Paul H.NinjaTrader Customer Service

                Comment


                  #9
                  I understand the whole idea to compare each Highs from the beginning and compare them to the variable, so the lowest values eliminate by themselves.

                  What in my code is right and what is wrong. First of all, is
                  double High = double.MinValue; is correctly used? When i use highPrice to compare with the variable does it check one by one starting from first to the left or the right side? Because in the output window the last number you see is the one closer to cursorx. At the top of the OW is the begginning of the index.

                  Finally i dont know what you mean by save. Arent they eleminating automatically? If first is 2809 > 2808, 2809 is kept than compare to 2807, etc.at the end only 2809 remain.
                  double highPrice = Bars.GetHigh(barIndex);

                  double High = double.MinValue;


                  if(highPrice > High)
                  {
                  Print(highPrice);
                  }

                  Comment


                    #10
                    Hello frankduc,

                    Thanks for your reply.

                    "double High = double.MinValue; is correctly used?" It is but I would not recommend using the variable name of High considering that there is a data series named High. You can validate the value by printing the value of the variable out after setting it to the min value which would be something like: -1.79769313486232E+308

                    So that I can best assist, please explain what your code is doing here as my assumption is that you are getting two different data X points from the cursor?

                    for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex++)
                    {
                    }


                    Is your intent to find the High on the chart from a cursor selection?
                    ​​​​​​​
                    Paul H.NinjaTrader Customer Service

                    Comment


                      #11
                      CursorX is where i click on the chart and someOtherInt is a number of bars that goes back from CursorX. If between CursorX and the beginning of the chart there is 200 bars.
                      someOtherInt is a ratio of those 200 bars. In this case about 2. Meaning that IndexBar represent 100 bars before CursorX.



                      What i want is the highest price in indexBar, the 100 bars prior to the 200.

                      Unfortunately,
                      Bars.GetHigh(barIndex); only give the high of each of those 100 bars. So the OW give me a list of those 100 highs for each bars. When all i want is the Highest High for all the 100 bars which represent in my case a trend. Meaning i want the price at the top of the trend.

                      According to you we can compare each highs one by one to get the highest of them all. I wish double.MaxValue could of been use to find the highest high.

                      So the way i see it if we do: (lets change High for Highest)

                      double highPrice = Bars.GetHigh(barIndex);
                      double Highest = double.MinValue;


                      if(highPrice > Highest)
                      {
                      Print(highPrice);
                      }

                      It returns values from the index but still not the one i seek. When you do highPrice > Highest, does it compare one by one each bars?
                      Any way how do
                      double.MinValue can compare the lowest value with another? Frankly, i dont see what code can come out with the answer.
                      Last edited by frankduc; 06-11-2019, 01:50 PM.

                      Comment


                        #12
                        Hello frankduc,

                        Thanks for your reply and clarification.

                        What you need to do is:
                        1) create/set your variable: double Highest = double.MinValue;
                        2) Begin the for-loop over the bars of interest.
                        3) In the for loop, get the bar high using double highPrice = Bars.GetHigh(barIndex); // I assume that you will set barIndex to be over the bars of interest
                        4) In the for-loop, if (highPrice>Highest) { Highest = highPrice;} // set new high when found
                        5) repeat 2 -4 until for-loop ends
                        6) Print value of Highest.

                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          If i understand correctly the code must look like this?

                          double highPrice = Bars.GetHigh(barIndex);

                          double Highest = double.MinValue;
                          for (int i = 0; i <= highPrice; i++)


                          if(highPrice > Highest) { Highest = highPrice;}
                          {
                          Print(Highest);

                          It still return 190 highs. Even if i repeat 2-4 the code will go on for a while before i get the highest high. This is not an automatic solution.
                          someOtherInt in barIndex will vary and change ratio. It could be 2, 3, 2.5 etc. Meaning that the number of bars in barIndex will change and the numbers of highs as well. To find the highest high i will have to return each time in the code to modify it. I need a solution that will give me automatically the highest high in barIndex.

                          Last edited by frankduc; 06-12-2019, 11:03 AM.

                          Comment


                            #14
                            Hello frankduc,

                            You have a double "highPrice" that has the High of your variable index "barIndex."

                            You have a double "Highest" that has a value of double.MinValue.

                            You then loop from 0 to "highPrice" (The High price of the bar you grabbed from the first line)

                            Inside the loop, you check if "highPrice" is greater than "Highest" and if it is, you set "Highest" to the value of "highPrice"

                            I do not think this is what you intend.

                            If you are trying to find the highest High of a bar within your range of indexes, you should loop through that range and see if that bar's High is greater than the last greatest High you saved. For example, building off of your snippet from post 1:

                            Code:
                            double highPrice;
                            int index;
                            
                            for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX) - someOtherInt; barIndex <= ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex++)
                            {                
                                if (Bars.GetHigh(barIndex) > highPrice)
                                {
                                    highPrice = Bars.GetHigh(barIndex);
                                    index = barIndex;
                                }
                            }
                            For a better visualization of BarsAgo indexes versus actual bar indexes, I suggest enabling these in your chart's Data Box.

                            Please let me know if you have any additional questions.
                            JimNinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ETFVoyageur, 05-18-2024, 12:45 AM
                            12 responses
                            63 views
                            0 likes
                            Last Post ETFVoyageur  
                            Started by armybender, 11-16-2023, 08:38 PM
                            12 responses
                            189 views
                            1 like
                            Last Post NinjaTrader_RyanS  
                            Started by Ryan333, Yesterday, 05:25 PM
                            4 responses
                            17 views
                            0 likes
                            Last Post Ryan333
                            by Ryan333
                             
                            Started by wuannetraam, Yesterday, 07:43 AM
                            8 responses
                            46 views
                            0 likes
                            Last Post wuannetraam  
                            Started by grebow25, Today, 09:20 AM
                            1 response
                            14 views
                            0 likes
                            Last Post NinjaTrader_LuisH  
                            Working...
                            X