Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Highest / Lowest Price within a certain Range; MIN(), MAX() Issue

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

    #16
    Hello JMont1,

    When calling Draw.HorizontalLine(), you can specify a the same drawing tag to update the drawing object to a new location so another drawing object is not created. For example:

    Code:
    bool firstbar = true;
    protected override void OnBarUpdate()
    {
        if(State == State.Historical)
            return;
    
        if (firstbar)
        {
            Draw.HorizontalLine(this, "MyTag", Close[0], Brushes.Red);
            firstbar = false;
        }
        else
            Draw.HorizontalLine(this, "MyTag", High[0], Brushes.Green);
    }
    Publicly available information on using drawing tools and Draw.HorizontalLine in particular can be found below.

    Drawing (Important notes at the bottom of the page - https://ninjatrader.com/support/help...us/drawing.htm

    Draw.HoriozontalLine() - https://ninjatrader.com/support/help...zontalline.htm

    Let us know if you have any additional questions.

    Comment


      #17
      Hi,

      I am using

      double highPrice = 0;
      double lowPrice = double.MaxValue;

      int lastBar = ChartBars.ToIndex;
      int firstBar = firstBarIdxToPaint; // this is the first bar of the session.

      for (int idx = firstBar; idx <= lastBar && idx >= firstBar; idx++)
      {
      highPrice = Math.Max(highPrice, Bars.GetHigh(idx));
      lowPrice = Math.Min(lowPrice, Bars.GetLow(idx));
      }


      but when I am printing the highPrice and lowPrice, it is printing some wrong prices. Any idea why that might happen? I am just trying to print the highest and lowest price for the session.

      Comment


        #18
        Hello asmmbillah,

        ChartBars.ToIndex is the index of the last bar that is visible on the chart. As it is relative to what is visible, I would not suggest using it to see what is the highest/lowest price of the session. I would instead suggest using it in OnBarUpdate which would be based on incoming data.

        You can save the CurrentBar index to a private variable on Bars.IsFirstBarOfSession, and then loop from that saved index to CurrentBar. Within the loop, you can use Math.Min and Math.Max like you are to track the highest high and lowest low.

        We look forward to assisting.

        Comment


          #19
          Using 1 minute time series need the first hour of session high/low... ideas anyone?

          Comment


            #20
            Hello elliot5,

            I would suggest adding a 60 minute data series, and then in BarsInProgress 1 (or the BarsInProgress associated with your 60 minute data series) to check Bars.IsFirstBarOfSession. You can then save the High[0] and Low[0] to variables and use them throughout your script.

            Multi Time Frame and Instruments - https://ninjatrader.com/support/help...nstruments.htm

            We look forward to assisting.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            597 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            343 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            556 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            555 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X