Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Confine processing to todays session

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

    Confine processing to todays session

    Hi,
    I am looking at the CurrentDayOHL indicator. Even though I might have 90 days of data on my chart I would like to only process data from yesterday and today.
    Basically I want lines indicating the high and low of the prior day and today. This built in indicator has a stair step appearance for every low on the chart which is distracting.

    Appreciate any help on this.
    Thanks.

    Code:
        public class CurrentDayOHL : Indicator
        {
            private DateTime                currentDate            =    Core.Globals.MinDate;
            private double                    currentOpen            =    double.MinValue;
            private double                    currentHigh            =    double.MinValue;
            private double                    currentLow            =    double.MaxValue;
            private DateTime                lastDate            =     Core.Globals.MinDate;
            private Data.SessionIterator    sessionIterator;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = NinjaTrader.Custom.Resource.NinjaScriptIndicatorDescriptionCurrentDayOHL;
                    Name                        = NinjaTrader.Custom.Resource.NinjaScriptIndicatorNameCurrentDayOHL;
                    IsAutoScale                    = false;
                    DrawOnPricePanel            = false;
                    IsOverlay                    = true;
                    IsSuspendedWhileInactive    = true;
                    ShowLow                        = true;
                    ShowHigh                    = true;
                    ShowOpen                    = true;
                    BarsRequiredToPlot            = 0;
    
                    AddPlot(new Stroke(Brushes.Goldenrod,    DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLOpen);
                    AddPlot(new Stroke(Brushes.SeaGreen,    DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLHigh);
                    AddPlot(new Stroke(Brushes.Red,            DashStyleHelper.Dash, 2), PlotStyle.Square, NinjaTrader.Custom.Resource.CurrentDayOHLLow);
                }
                else if (State == State.Configure)
                {
                    currentDate            = Core.Globals.MinDate;
                    currentOpen            = double.MinValue;
                    currentHigh            = double.MinValue;
                    currentLow            = double.MaxValue;
                    lastDate            = Core.Globals.MinDate;
                }
                else if (State == State.DataLoaded)
                {
                    sessionIterator = new SessionIterator(Bars);
                }
                else if (State == State.Historical)
                {
                    if (!Bars.BarsType.IsIntraday)
                    {
                        Draw.TextFixed(this, "NinjaScriptInfo", Custom.Resource.CurrentDayOHLError, TextPosition.BottomRight);
                        Log(Custom.Resource.CurrentDayOHLError, LogLevel.Error);
                    }
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (!Bars.BarsType.IsIntraday) return;
    
                lastDate         = currentDate;
                currentDate     = sessionIterator.GetTradingDay(Time[0]);
    
                if (lastDate != currentDate || currentOpen == double.MinValue)
                {
                    currentOpen        = Open[0];
                    currentHigh        = High[0];
                    currentLow        = Low[0];
                }
    
                currentHigh            = Math.Max(currentHigh, High[0]);
                currentLow            = Math.Min(currentLow, Low[0]);
    
                if (ShowOpen)
                    CurrentOpen[0] = currentOpen;
    
                if (ShowHigh)
                    CurrentHigh[0] = currentHigh;
    
                if (ShowLow)
                    CurrentLow[0] = currentLow;
            }

    #2
    Hello Grantx,

    Thank you for your post.

    If I'm understanding correctly, you're looking for a display like the Prior Day OHLC indicator, where it plots whatever the high and low are as a straight line, is that correct? Do you only want it to plot for the current day or do you want it to plot historically? You may be able to locate a premade version of what you're looking for on our User App Share as well, which is publicly accessible here:



    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thank you Kate for getting back to me.
      I have found code in the shared repository but never doing exactly what Im after. .Since my 1st post Ive managed to work out how to obtain OHLC data. Now I would like to display it as in the attached screenshot. So basically how would I draw a straight line from the right edge of the chart which extends to the start of the session only (not extending across the entire chart). Or even better, the line never touches price but remains cropped and right aligned with a text label.

      The indicators I downloaded all have this dot or dashed thing going on.Just a line with a label is what Im after.

      Many thanks.
      Attached Files

      Comment


        #4
        Hello Grant,

        Thank you for your reply.

        I'd advise taking a look at how the built in Pivots indicator renders the pivot lines. You would likely be able to modify that to fit your uses. I would specifically focus on how it plots lines and text in On Render() as this could certainly be modified to display your high and low lines instead of the pivots.

        Please let us know if we may be of further assistance to you.

        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