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


plot daily open value on vol chart

  • Filter
  • Time
  • Show
Clear All
new posts

    plot daily open value on vol chart


    Have searched forums but can't find my answer.

    I want to plot the days open on a volume chart (along with 1st hrs high / low) etc.

    The High low and median are fine, (adapted from the FHHRange indicator on this site) but because the volume bar may or may not be completed at 9.30am the value for the open is variable to say the least. I am currently using the open of the bar that is being formed at 9.30 so this can be 3, 4 or more ticks away from the real value.

    Can someone point me in the right direction please. Code so far is:

    #region Variables

    private int startHour = 9; // Default setting for StartHour
    private int startMinute = 30; // Default setting for StartMinute
    private int endHour = 10; // Default setting for EndHour
    private int endMinute = 30; // Default setting for EndMinute


    protected override void Initialize()
    Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "HighestHigh"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Yellow), PlotStyle.Line, "LowestLow"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Cross, "TodaysOpen"));
    Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Line, "MidLine"));

    CalculateOnBarClose = true;
    Overlay = true;
    PriceTypeSupported = false;

    private DateTime startDateTime;
    private DateTime endDateTime;

    protected override void OnBarUpdate()
    // Check to make sure the end time is not earlier than the start time
    if (EndHour < StartHour)

    //Do not calculate the high or low value when the ending time of the desired range is less than the current time of the bar being processed
    if (ToTime(EndHour, EndMinute, 0) > ToTime(Time[0]))

    // If the stored date time date is not the same date as the bar time date, create a new DateTime object
    if (startDateTime.Date != Time[0].Date)
    startDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, StartHour, StartMinute, 0);
    endDateTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, EndHour, EndMinute, 0);

    // Calculate the number of bars ago for the start and end bars of the specified time range
    int startBarsAgo = GetBar(startDateTime);
    int endBarsAgo = GetBar(endDateTime);

    // Now that we have the start end end bars ago values for the specified time range we can calculate the highest high for this range
    double highestHigh = MAX(High, startBarsAgo - endBarsAgo)[endBarsAgo];

    // Now that we have the start end end bars ago values for the specified time range we can calculate the lowest low for this range
    double lowestLow = MIN(Low, startBarsAgo - endBarsAgo)[endBarsAgo];

    //Gets the value for todays open
    double todaysOpen = Open[startBarsAgo];

    // Set the plot values
    MidLine.Set(highestHigh - ((highestHigh - lowestLow)/2));


    Hi stocktraderbmp,

    Have you tried the built-in CurrentDayOHL() indicator? That has the open for the current session, designed for intraday charts.

    You could also grab it with something with BarsSinceSession like.
    double mySessionOpen = Open[Bars.BarsSinceSession];
    Ryan M.NinjaTrader Customer Service


      Thanks Ryan again .....

      I have tried the built in OHL but it plots the High and low for the day not the 1st hours range which is why I adapted someone else's. I seem to recall, though I'm not sure of this, that the open was calculated from the bar with the min value - I assume that it was referencing the first bar of RTH - which would work on a minute derived chart but a volume bar maybe 1/2 way through construction when the bell tolls - so to speak ie a volume bar is not time dependent so the days open value needs to be sourced from elsewhere.
      Will try the bars idea tomorrow and will follow the link you gave me in the email but my initial fear is that I am still going to be referencing a bar that did not have a convenient start time of exactly 09:30 and I will have to try to 'Get...' the value from another source that does open a bar at exactly 09:30.

      Thanks again,



        I see. Thanks for the reply. As you note, the time stamp of bars will be variable with volume chart. If your goal is to get some values for the first hour of trading, then you should be working with a time series instead of volume. To get high/low of a time range, this sample can help:

        You could work it into a multiseries NinjaScript if you wanted to combine this value with some other parts of a volume based script.
        Ryan M.NinjaTrader Customer Service


          Thank you for coming back to me Ryan;

          I guess I have confused the issue slightly - I am only looking for one value - the official open for the current day.

          I have already plotted the high and low as per the code shown and I have a value for the open of the bar that WAS IN THE PROCESS of being completed at 09:30. But as this bar could have started at 09:29 the value for my plot is inaccurate.

          HOW do I get an accurate value please ?



            Thanks for clarifying. The open for first bar of session on intraday chart is:
            double mySessionOpen = Open[Bars.BarsSinceSession];

            That will work on volume charts as well.
            Ryan M.NinjaTrader Customer Service


              Thanks Ryan,

              Will try that.



                Hi again;

                The code you suggested works perfectly if the session template is set to RTH in the data series window - BUT if any one else is following this you will need to set your own session template up in the session manager adding an extra session to cover Sunday open to Monday open and adjust all the other openings accordingly if you want to have the extended trading hours plotted.

                Thanks again for your help;



                Latest Posts


                Topics Statistics Last Post
                Started by TAJTrades, Today, 06:12 AM
                1 response
                Last Post NinjaTrader_Jim  
                Started by jack121, Yesterday, 05:59 PM
                1 response
                Last Post NinjaTrader_PaulH  
                Started by trader3000a, Today, 04:23 AM
                0 responses
                Last Post trader3000a  
                Started by apratm, Today, 03:05 AM
                3 responses
                Last Post apratm
                by apratm
                Started by 05arminia, Today, 02:48 AM
                1 response
                Last Post NinjaTrader_Marco