Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by TheWhiteDragon, 01-21-2019, 12:44 PM
        4 responses
        542 views
        0 likes
        Last Post PaulMohn  
        Started by GLFX005, Today, 03:23 AM
        0 responses
        3 views
        0 likes
        Last Post GLFX005
        by GLFX005
         
        Started by XXtrader, Yesterday, 11:30 PM
        2 responses
        11 views
        0 likes
        Last Post XXtrader  
        Started by Waxavi, Today, 02:10 AM
        0 responses
        7 views
        0 likes
        Last Post Waxavi
        by Waxavi
         
        Started by TradeForge, Today, 02:09 AM
        0 responses
        14 views
        0 likes
        Last Post TradeForge  
        Working...
        X