Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

plot daily open value on vol chart

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

    plot daily open value on vol chart

    Hi;

    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

    #endregion

    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)
    return;

    //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]))
    return;

    // 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
    HighestHigh.Set(highestHigh);
    LowestLow.Set(lowestLow);
    TodaysOpen.Set(todaysOpen);
    MidLine.Set(highestHigh - ((highestHigh - lowestLow)/2));

    }

    #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

    Comment


      #3
      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,

      Ben.

      Comment


        #4
        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:
        http://www.ninjatrader.com/support/f...4911#post44911

        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

        Comment


          #5
          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 ?

          Ben.

          Comment


            #6
            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

            Comment


              #7
              Thanks Ryan,

              Will try that.

              Ben

              Comment


                #8
                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;

                Ben.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by salination2, Yesterday, 07:21 PM
                2 responses
                6 views
                0 likes
                Last Post salination2  
                Started by aarons34, Yesterday, 08:11 PM
                0 responses
                7 views
                0 likes
                Last Post aarons34  
                Started by Shiner452, Yesterday, 06:55 PM
                0 responses
                3 views
                0 likes
                Last Post Shiner452  
                Started by Aquatrade, Yesterday, 06:22 PM
                0 responses
                3 views
                0 likes
                Last Post Aquatrade  
                Started by trader3000a, Yesterday, 02:04 PM
                2 responses
                26 views
                0 likes
                Last Post trader3000a  
                Working...
                X