Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Time definable OHLC

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

    Time definable OHLC

    I have an pit time definable OHLC indictor which is "sort of working". I wonder if someone can help me iron out some problems.

    This indicator basically allows you to define the pit open and pit close, so that it plots the OHLC figures from the pit traded session only, ignoring the Globex.

    The problems -

    1) The first issue is annoying, but can be worked around - However, I believe there must be a way of defining the correct start/end time. At the moment if you put in 09:00 as the start time on a 1min chart, it will actually plot the OPEN line at 08:59 because of the way the Ninja Time Stamping works - So, to get it to plot the Open at the correct time of 09:00est you need to input a start time of 09:01

    This is not ideal and is an annoyance. Other indicators I have seem to allow for the Ninja TimeStamping, and I have never had to offset the time before.

    Anyone point me how to resolve this in the code?

    I admit, this is just an annoyance and it´s not really a big deal to just add the "chart time interval" to the values of open and close. Would be nice to fix it though :-)

    Number 2 is a problem which I can´t find a workaround for.

    2) The indicator does not plot correctly if you have an instrument which starts off on a non round number pit session start time - GC for instance starts at 08:20am EST.... Going by the above (1) theory I currently should have to put the start time as 08:21am, I do this but it still doesn´t plot the start time correctly, unless the chart has a time interval which is divisible by the number of minutes, for anything other than 1m this is hard to do.

    For example, if I input 08:21 then it only plots correctly if I chose a 1minute or a 21minute time interval. If I input 08:20 as the start time, then it only plots correctly if I use a 1min, 2min, 5min, 10min chart interval. If I input 08:15 as the start time then it only plots the line if I use a 1, 3 or 5minute chart.

    Pretty sure there are likely easy fixes for both of these, but I am stumped.

    Appreciate any help. I am hoping these indicators would be very useful to many who want to plot the OHLC of the Pit Session, yet plot all the Globex session on charts.


    Below attached is the current code.


    Code:
        {
            #region Variables
    
            // Wizard generated variables
            // User defined variables (add any user defined variables below)
            private DateTime     currentDate     = Cbi.Globals.MinDate;
            private double        currentOpen        = 0;
            private double        currentHigh        = 0;
            private double        currentLow        = 0;
            private double        currentClose    = 0;
            private double        priordayOpen    = 0;
            private double        priordayHigh    = 0;
            private double        priordayLow        = 0;
            private double        priordayClose    = 0;
            private bool        showOpen        = true;
            private bool        showHigh        = true;
            private bool        showLow            = true;
            private bool        showClose        = true;
            #endregion
    
            int dayStart = 800;
            int dayEnd = 2200;
            int onDay = 0;
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                Add(new Plot(Color.Orange, PlotStyle.Hash, "Prior Open"));
                Add(new Plot(Color.Green, PlotStyle.Hash, "Prior High"));
                Add(new Plot(Color.Red, PlotStyle.Hash, "Prior Low"));
                Add(new Plot(Color.Firebrick, PlotStyle.Hash, "Prior Close"));
    
                Plots[0].Pen.DashStyle = DashStyle.Dash;
                Plots[3].Pen.DashStyle = DashStyle.Dash;
                
                AutoScale             = false;
                Overlay                = true;      // Plots the indicator on top of price
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (Bars == null)
                    return;
    
                if (!Bars.BarsType.IsIntraday)
                {
                    DrawTextFixed("error msg", "PriorDayOHLC only works on intraday intervals", TextPosition.BottomRight);
                    return;
                }
    
    
                //if (onDay != Time[0].Day)
                //{
                //    if (currentOpen != 0)
                //    {
                //        priordayOpen = currentOpen;
                //        priordayHigh = currentHigh;
                //        priordayLow = currentLow;
                //        priordayClose = currentClose;
    
                //        if (ShowOpen) PriorOpen.Set(priordayOpen);
                //        if (ShowHigh) PriorHigh.Set(priordayHigh);
                //        if (ShowLow) PriorLow.Set(priordayLow);
                //        if (ShowClose) PriorClose.Set(priordayClose);
                //    }
    
                //    onDay = Time[0].Day;
                //}
                //else
                //{
                //}
    
                // If the current data is not the same date as the current bar then its a new session
                if (currentDate != Bars.GetTradingDayFromLocal(Time[0]) || currentOpen == 0)
                {
                    // The current day OHLC values are now the prior days value so set
                    // them to their respect indicator series for plotting
                    if (currentOpen != 0)
                    {
                        priordayOpen = currentOpen;
                        priordayHigh = currentHigh;
                        priordayLow = currentLow;
                        priordayClose = currentClose;
    
                        if (ShowOpen) PriorOpen.Set(priordayOpen);
                        if (ShowHigh) PriorHigh.Set(priordayHigh);
                        if (ShowLow) PriorLow.Set(priordayLow);
                        if (ShowClose) PriorClose.Set(priordayClose);
                    }
    
                    // Initilize the current day settings to the new days data
                    currentOpen = Open[0];
                    currentHigh = High[0];
                    currentLow = Low[0];
                    currentClose = Close[0];
    
                    currentDate = Bars.GetTradingDayFromLocal(Time[0]);
                }
                else // The current day is the same day
                {
                    if (ToTime(Time[0]) == dayStart * 100) currentOpen = Open[0];
    
                    if (ToTime(Time[0]) > dayStart * 100 && ToTime(Time[0]) < dayEnd * 100)
                    {
                        // Set the current day OHLC values
                        currentHigh = Math.Max(currentHigh, High[0]);
                        currentLow = Math.Min(currentLow, Low[0]);
                        currentClose = Close[0];
                    }
    
                    if (ShowOpen) PriorOpen.Set(priordayOpen);
                    if (ShowHigh) PriorHigh.Set(priordayHigh);
                    if (ShowLow) PriorLow.Set(priordayLow);
                    if (ShowClose) PriorClose.Set(priordayClose);
                }
            }
    
            #region Properties
    
            [Description("")]
            [Category("Parameters")]
            public int DayStart
            {
                get { return dayStart; }
                set { dayStart = Math.Max(0, value); }
            }
    
            [Description("")]
            [Category("Parameters")]
            public int DayStop
            {
                get { return dayEnd; }
                set { dayEnd = Math.Max(1, value); }
            }
    
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries PriorOpen
            {
                get { return Values[0]; }
            }
    
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries PriorHigh
            {
                get { return Values[1]; }
            }
    
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries PriorLow
            {
                get { return Values[2]; }
            }
    
            [Browsable(false)]    // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
            [XmlIgnore()]        // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
            public DataSeries PriorClose
            {
                get { return Values[3]; }
            }
            
            [Browsable(true)]
            [Gui.Design.DisplayNameAttribute("Show open")]
            public bool ShowOpen
            {
                get { return showOpen; }
                set { showOpen = value; }
            }
            
            [Browsable(true)]
            [Gui.Design.DisplayNameAttribute("Show high")]
            public bool ShowHigh
            {
                get { return showHigh; }
                set { showHigh = value; }
            }
            
            [Browsable(true)]
            [Gui.Design.DisplayNameAttribute("Show low")]
            public bool ShowLow
            {
                get { return showLow; }
                set { showLow = value; }
            }
            
            [Browsable(true)]
            [Gui.Design.DisplayNameAttribute("Show close")]
            public bool ShowClose
            {
                get { return showClose; }
                set { showClose = value; }
            }
    
            #endregion
        }
    }

    #2
    Hi Scottie,

    I have coded such an indicator, which plots the OHL with Fibonacci levels, average daily noise and average daily range. The indicator works with a session template that subdivides the full electronic session into the regular session and a pre-session and post-session where applicable.

    The advantage of using a session template is that it cuts off the bar at the session break. You will therefore get the exact values for the high and low. Without the use of a session template bars will overlap and you may not get the correct values from the primary bar series. In this case you would need to code a multi-timeframe indicator that loads a secondary bar series of 1-minute data. You could then perform the calculations on the minute data and show the result on your chart bars.

    To avoid this hassle, the session template is well suited. Below is an example for the regular session of CL 05-13. The indicator allows you to identify the following

    - regular high
    - regular low
    - regular open
    - midline and fib retracements calculated from high and low
    - noise bands based on average daily noise over the last N days
    - target bands either based on average daily expansion or average daily range of the last N days

    Noise bands: Looking at the failed move every day. The failed move is the smaller of (High - Open) and (Open-Low). The failed moves are averaged over N days and added to or subtracted from the regular open.

    Average daily expansion: Looking at the larger move from the open every day. The larger move is the greater of (High - Open) and (Open-Low). The larger moves are averaged over N days and added to or subtracted from the regular open.

    Average daily range: The daily range of the RTH session is averaged over the last N days and added to the current low or subtracted from the currnet high. The target bands show when price hits the level corresponding to the average daily RTH range of the last N days.

    Below is a sample chart attached. The indicator can be found here:



    The package further include weekly, monthly indicators which all can be set to RTH or ETH with the same session template.
    Attached Files

    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