StartHour = 8;
StartMinute = 30;
EndHour = 10;
EndMinute = 30;
AddPlot(Brushes.Green, "HighestHigh");
AddPlot(Brushes.Red, "LowestLow");
}
}
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 = Bars.GetBar(startDateTime);
int endBarsAgo = Bars.GetBar(endDateTime);
/* Now that we have the start and end bars ago values for the specified time range we can calculate the highest high for this range
Note: We add 1 to the period range for MAX and MIN to compensate for the difference between "period" logic and "bars ago" logic.
"Period" logic means exactly how many bars you want to check including the current bar.
"Bars ago" logic means how many bars we are going to go backwards. The current bar is not counted because on that bar we aren't going back any bars so it would be "bars ago = 0" */
double highestHigh = MAX(High, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
// Now that we have the start and end bars ago values for the specified time range we can calculate the lowest low for this range
double lowestLow = MIN(Low, endBarsAgo - startBarsAgo + 1)[CurrentBar - endBarsAgo];
// Set the plot values
HighestHigh[0] = highestHigh;
LowestLow[0] = lowestLow;
}
region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> HighestHigh
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> LowestLow
{
get { return Values[1]; }
}
Comment