namespace NinjaTrader.NinjaScript.Indicators
{
public class RangeDefiner : Indicator
{
private Series<double> highPrice;
private Series<double> lowPrice;
private double rangeHigh = 0.0;
private double rangeLow = 0.0;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"An indicator to find and define price ranges on a chart.";
Name = "RangeDefiner";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
RangePeriod = 10;
AddPlot(Brushes.Green, "RangeHigh");
AddPlot(Brushes.Red, "RangeLow");
}
else if (State == State.DataLoaded)
{
// Initialize the high and low price data series
highPrice = new Series<double>(this, MaximumBarsLookBack.Infinite);
lowPrice = new Series<double>(this, MaximumBarsLookBack.Infinite);
}
}
protected override void OnBarUpdate()
{
// Get the highest and lowest prices for the specified period
double rangeHigh = MAX(RangePeriod)[0];
double rangeLow = MIN(RangePeriod)[0];
// RangeHigh = rangeHigh;
// RangeLow = rangeLow;
}
region Properties
[NinjaScriptProperty]
[Range(0, double.MaxValue)]
[Display(Name="RangePeriod", Order=0, GroupName="Parameters")]
public double RangePeriod
{ get; set; }
[Browsable(false)]
[XmlIgnore]
public Series<double> RangeHigh
{
get { return Values[0]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> RangeLow
{
get { return Values[1]; }
}
#endregion
}
}

Comment