Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

easiest and simple way to calculate todays range

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

    easiest and simple way to calculate todays range

    Hi all,

    what is the easiest way to display the highest high and lowest low of an intraday session? for example: let's say today the market had a low at 3.000 points and the high at 3.500. I'd like to have the result 500 into a variable called "todaysRange" so I can draw.textfixed it onto a corner. I already looked into the indicator "CurrentDayOHL" but this looks oversized and confusing to me.

    Is there a simpler way to achieve this? I want to add that I want to have it worked in mode "calculate on price change" because I don't want to wait until a 60min bar finishes. Any clues?

    EDIT: I guess I've found a solution

    Code:
    int highestBarsAgo = HighestBar(High, Bars.BarsSinceNewTradingDay);
    int lowestBarsAgo = LowestBar(Low, Bars.BarsSinceNewTradingDay);
    double todaysRange = High[highestBarsAgo]-Low[lowestBarsAgo];
    is that a suitable solution or would you suggest another approach ?
    Last edited by patricia70; 12-29-2020, 01:48 PM.

    #2
    Hello patricia70,

    Thanks for your post.

    You might consider using the Range indicator, based on daily bars. This will draw a bar graph of the points range of each day.

    If you only need a number then I would suggest using the market analyzer with the indicator column and select the Range indicator based on daily bar.

    Otherwise to Draw.TextFixed on the chart you would need to create a custom indicator. You could use the CurrentDayOHL for this with a smaller time frame or use Range() indicator with daily bars.

    Alternatively, you could create this in the Strategy Builder however you would have to run this as a strategy meaning it would need to be Enabled on each restart of Ninjatrader.

    Comment


      #3
      Hi Paul,

      although I solved it with the 3-liner which I guess you didn't see yet in my initial edited post, I looked into your reply. Due to performance reasons and what I'm trying to achieve I'd prefer to go the way with the "Draw.TextFixed" as you mentioned. Thanks a lot for the hint with CurrentDayOHL, I totally forgot that this is a method and I can call it from my own indicator and feed it to whatever I want. So said, this code brought the result as desired:

      Code:
      string intradayHigh = CurrentDayOHL().CurrentHigh[0].ToString();
      string intradayLow = CurrentDayOHL().CurrentLow[0].ToString();
      Draw.TextFixed (this, ...)
      This version is a 2-liner and so simpler than my one. I'll take your suggestion thank you!

      Comment


        #4
        Hello patricia70,

        Thanks for your reply.

        As you are seeing there is more than one way to accomplish the same thing.

        In the case of the code in post 3, I would suggest that this is an area to discuss. Assuming you are showing that exmple is in OnBarUpdate(), the code would create two copies of the CurrentDayOHL indicator. (and if you used it in other places in OnBarUpdate, for each use it would create another copy), so this would not be efficient resource use.

        The "best practice" would be to create a private instance of the indicator and initialise the indicator in State.DataLoaded (or state.Historical) and then use the private instance in OnBarUpdate(). Another minor advantage is that you can name it anything (and that allows for smaller names, less typing!).

        Example:
        At the class level: private CurrentDayOHL myCD;

        In state.dataLoaded: myCD = CurentDayOHL();

        In OnBarUpdate()

        string intradayHigh = myCD.CurrentHigh[0].ToString();
        string intradayLow = myCD.CurrentLow[0].ToString();


        Please see "referencing indicator methods" here: https://ninjatrader.com/support/help...tm#Performance

        Comment


          #5
          Hello Paul,

          thanks for pointing out. The only part that I didn't understand yet is following:
          Code:
          [I]private CurrentDayOHL myCD;[/I]
          can you explain this line in detail ,please? I do not understand when and why "public" or "private" should be used, nor I understand the 2nd string "CurrentDayOHL" in this line.

          Finally, I decided to choose the way you suggested HERE.

          Comment


            #6
            Hello patricia70,

            Thanks for your reply.

            The line is saying I want to create a private instance of the indicator CurrentDayOHL called myCD. The same thing is shown in the best practices link previously provided and in there the example is using an SMA. and creating a private SMA mySMA;.

            We use private as we are not making its output available outside the script.





            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            576 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            334 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
            553 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            551 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X