regards
NH
{
#region Variables
// Wizard generated variables
private int startHour = 9; // Default setting for StartHour
private int startMinute = 15; // Default setting for StartMinute
private int endHour = 9; // Default setting for EndHour
private int endMinute = 20; // Default setting for EndMinute
private bool runonce = true;
// User defined variables (add any user defined variables below)
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "HighestHigh"));
Add(new Plot(new Pen(Color.Red, 2), PlotStyle.Line, "LowestLow"));
CalculateOnBarClose = false;
Overlay = true;
PriceTypeSupported = false;
}
private DateTime startDateTime;
private DateTime endDateTime;
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
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);
}
if (//startDateTime.DayOfWeek.ToString() == "Saturday" ||
startDateTime.DayOfWeek.ToString() == "Sunday") return;
// 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];
// Set the plot values
HighestHigh.Set(highestHigh);
LowestLow.Set(lowestLow);
}
/// --------------------------------------------------------------------------------
/// --------------------------------------------------------------------------------
/// In order to trim the indicator's label we need to override the ToString() method.
public override string ToString()
{
/* We return a label consisting of only the parameters we want to include. If we did not
override this method we would have a label with all four parameters. In this example we will
be left with only the parameters "Period" and "Interval". */
return Name;
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries HighestHigh
{
get { return Values[0]; }
}
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries LowestLow
{
get { return Values[1]; }
}
[Description("")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("2. Start Hour")]
public int StartHour
{
get { return startHour; }
set { startHour = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("3. Start Minute")]
public int StartMinute
{
get { return startMinute; }
set { startMinute = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("4. End Hour")]
public int EndHour
{
get { return endHour; }
set { endHour = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
[Gui.Design.DisplayNameAttribute("5. End Minute")]
public int EndMinute
{
get { return endMinute; }
set { endMinute = Math.Max(1, value); }
}
#endregion
}
}
Comment