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));
}
Comment