I'm trying to add some functions this "GetHighLowByTimeRange" Indicator.
Fist I need to calculate two drawn lines region,
Then I need to add condition like that;
- if region more then "15" color that region "red"
- if region less then "15" color that region "green"
Also I need change that "15" in indicator settings tab and I need to get that value in Plot value for use Strategy Builder.
Thanks for your help.
Code Part
-------------------
#region Using declarations
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
///
/// </summary>
[Description("")]
public class GetHighLowByTimeRange : Indicator
{
#region Variables
// Wizard generated 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 = 15; // Default setting for EndMinute
// 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(Color.FromKnownColor(KnownColor.Green), PlotStyle.Line, "HighestHigh"));
Add(new Plot(Color.FromKnownColor(KnownColor.Red), PlotStyle.Line, "LowestLow"));
CalculateOnBarClose = true;
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);
}
// 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 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, startBarsAgo - endBarsAgo + 1)[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, startBarsAgo - endBarsAgo + 1)[endBarsAgo];
// Set the plot values
HighestHigh.Set(highestHigh);
LowestLow.Set(lowestLow);
}
#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")]
public int StartHour
{
get { return startHour; }
set { startHour = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int StartMinute
{
get { return startMinute; }
set { startMinute = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int EndHour
{
get { return endHour; }
set { endHour = Math.Max(1, value); }
}
[Description("")]
[Category("Parameters")]
public int EndMinute
{
get { return endMinute; }
set { endMinute = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
----------------
Comment