I'm trying to gauge how easy it would be to adjust this a (4) hour timeframe. ie: capturing the high and low of each 4 hour period instead of 1 hour.
Would this be a quick change using the code below... or much more complex than just changing a few things...?
Any help or guidance would be great!
CODE BLOCK:
/// <summary>
/// Dynamically plots the highest and lowest of the current hour.//
/// </summary>
public class HourlyHL : Indicator
{
private int startOfHourBarIndex = -1;
private int currentHour = -1;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = "Plots the highest and lowest bars for each hour.";
Name = "Hourly High Low";
IsAutoScale = false;
DrawOnPricePanel = false;
IsOverlay = true;
IsSuspendedWhileInactive = true;
// AddPlot for Hourly High
AddPlot(new Stroke(Brushes.SpringGreen, 2), PlotStyle.Square, "Hourly High");
// AddPlot for Hourly Low
AddPlot(new Stroke(Brushes.OrangeRed, 2), PlotStyle.Square, "Hourly Low");
}
}
protected override void OnBarUpdate()
{
DateTime hourBeginning = Time[0].AddMinutes(-1 * Time[0].Minute).AddSeconds(-1 * Time[0].Second);
int hour = hourBeginning.Hour;
if (hour != currentHour)
{
// Start of a new hour, reset startOfHourBarIndex
currentHour = hour;
startOfHourBarIndex = CurrentBar;
}
// Calculate how many bars ago the current hour started
int hourBeginBarsAgo = CurrentBar - startOfHourBarIndex;
if (hourBeginBarsAgo >= 0)
{
double highestHigh = MAX(High, hourBeginBarsAgo + 1)[0];
double lowestLow = MIN(Low, hourBeginBarsAgo + 1)[0];
for (int index = 0; index <= hourBeginBarsAgo; index++)
{
Values[0][index] = highestHigh;
Values[1][index] = lowestLow;
}
}
}
}
}

Comment