Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting previous high & low

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

    Getting previous high & low

    Hi,

    I'm trying to get the Yesterday low from an indicator like this

    Code:
    public void test()
    {
    double value = PriorDayOHLC().PriorLow[0];
    Print("The prior session low value is " + value.ToString());
    }

    Buy I'm always getting 0.

    Why?

    Thks​

    #2
    Hello Powerbucker,

    Do you have enough data loaded where you are testing the script?

    Comment


      #3
      Yes, the chart is completely loaded.

      Do you have some indicator sample for use this?

      Thanks

      Comment


        #4
        Hello Powerbucker,

        Are you using an intraday chart? The indicator requires that you have previous sessions of data loaded in the chart so it can process and also that it is an intraday chart. There is no specific premade sample for that indicator, the help guide shows how to use it in code beyond that you would just need to make sure its data requirements are met.

        Comment


          #5
          Yes I'm using on a intraday chart of M5. Is needed I attach the PriorDayOHLC​ indicator on my chart. Anything else I have to do to use this function?

          Comment


            #6
            Hello Powerbucker,

            You can apply it to the chart to see if it plots based on the chart settings that you used but that is not required for NinjaScript use.

            Comment


              #7
              I've seen that the problem is that I'm using the PriorDayOHLC() function in a public "Test()" function of the indicator. From an addon I look for the indicator and call the Test() function.

              In that case it doesn't work.

              If I do it from an event of the indicator, such as OnBarUpdate, it does work.

              Any ideas?​

              Comment


                #8
                Hello Powerbucker,

                Indicators are not intended to be used with addons, they can be used from strategies, other indicators or the market analyzer columns.

                Comment


                  #9
                  Ok, so if from the indicator I want to get the maximum and minimum of the previous day when the indicator starts, in what event can I do it? State.Realtime? DataLoaded?

                  Comment


                    #10
                    Hello Powerbucker,

                    To have the indicator calculate that, it needs to be called from OnBarUpdate. You need to call the indicator to access its plot so it can iterate the data and calculate the previous day's OHLC values.

                    Comment


                      #11
                      Ok, and the last question (I promise). How can I get the high or low of the last X bars?

                      Now I'm doing like this:

                      Code:
                      double lastHigh = double.MinValue;
                      double lastLow = double.MaxValue;
                      ​numBars = 10;
                      
                      for (int i = Bars.Count - 1; i >= 0; i--)
                      {
                      barsCount++;
                      
                      lastHigh = Math.Max(lastHigh, Bars.GetHigh(i));
                      lastLow = Math.Min(lastLow, Bars.GetLow(i));
                      
                      if (barsCount >= numBars)
                      break;
                      }
                      ​
                      Is correct or there is a better way?

                      Comment


                        #12
                        Hello Powerbucker,

                        You can use HighestBar and LowestBar for that.



                        Comment


                          #13
                          Thank you very much, Jesse !!

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                          0 responses
                          558 views
                          0 likes
                          Last Post Geovanny Suaza  
                          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                          0 responses
                          324 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by Mindset, 02-09-2026, 11:44 AM
                          0 responses
                          101 views
                          0 likes
                          Last Post Mindset
                          by Mindset
                           
                          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                          0 responses
                          545 views
                          1 like
                          Last Post Geovanny Suaza  
                          Started by RFrosty, 01-28-2026, 06:49 PM
                          0 responses
                          547 views
                          1 like
                          Last Post RFrosty
                          by RFrosty
                           
                          Working...
                          X