Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Current Day Opening Range

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

    Current Day Opening Range

    Hello,

    I am wondering how to modify the existing CurrentDayOHL indicator so that it plots the opening range of the first 1 min candle only. So, I would like a horizontal line on the chart for the rest of the day from the first 1 minute candle or 30 second candle high and low. And I would also only like to have the current day 1min or 30sec OR plot, no previous days. Can anyone help me modify the starter script to do this?

    Thanks

    #2
    Hello adtdt,

    Welcome to the forums!

    I believe you have an easier time accomplishing the task starting fresh.

    You will want to know the range for the first bar of an added data series and then you will want to draw a line based on that range using NinjaTrader's Drawing Tools.

    Working with Multi Time Frame scripts - https://ninjatrader.com/support/help...nstruments.htm

    Bars.IsFirstBarOfSession - https://ninjatrader.com/support/help...rofsession.htm

    Drawing - https://ninjatrader.com/support/help...8/?drawing.htm

    To give you some further direction, you could try something like the following to get started.

    Code:
    public class DrawOpeningRange : Indicator
    {
        protected override void OnStateChange()
        {
            if (State == State.SetDefaults)
            {
                Description                                    = @"Enter the description for your new custom Indicator here.";
                Name                                        = "DrawOpeningRange";
                Calculate                                    = Calculate.OnBarClose;
                IsOverlay                                    = true;
                DrawOnPricePanel                            = true;
            }
            else if (State == State.Configure)
            {
                AddDataSeries(BarsPeriodType.Minute, 1);
                AddDataSeries(BarsPeriodType.Second, 30);
            }
        }
    
        private bool bMinuteOrSecond = true;
        private double open, high, low, close;
        private int startBar = -1;
    
        protected override void OnBarUpdate()
        {
            if (BarsInProgress == 1 && bMinuteOrSecond)
            {
                if (Bars.IsFirstBarOfSession)
                {
                    open = Open[0];
                    high = High[0];
                    low = Low[0];
                    close = Close[0];
                    startBar = CurrentBars[0];
                }
            }
    
            if (BarsInProgress == 2 && !bMinuteOrSecond)
            {
                if (Bars.IsFirstBarOfSession)
                {
                    open = Open[0];
                    high = High[0];
                    low = Low[0];
                    close = Close[0];
                    startBar = CurrentBars[0];
                }
            }
    
            if (BarsInProgress == 0 && startBar > 0)
            {
                Draw.Line(this, "open", CurrentBar-startBar, open, 0, open, Brushes.Green);
                Draw.Line(this, "high", CurrentBar-startBar, high, 0, high, Brushes.Green);
                Draw.Line(this, "low", CurrentBar-startBar, low, 0, low, Brushes.Green);
                Draw.Line(this, "close", CurrentBar-startBar, close, 0, close, Brushes.Green);
            }
        }
    }
    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
    571 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    330 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
    548 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    548 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X