namespace NinjaTrader.NinjaScript.Indicators
{
public class NBar15MinuteHL : Indicator
{
#region Private Variables
private int highestBarsAgo;
private double highestPrice;
private int lowestBarsAgo;
private double lowestPrice;
#endregion
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Highest High/Lowest Low of last n bars on 15 min chart";
Name = "NBar15MinuteHL";
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;
NBars = 3;
AddLine(Brushes.Lime, 1, "High");
AddLine(Brushes.Red, 1,"Low");
}
else if (State == State.Configure)
{
AddDataSeries(Data.BarsPeriodType.Minute, 15);
}
}
protected override void OnBarUpdate()
{
//Add your custom indicator logic here.
if (CurrentBar<NBars)
return;
highestBarsAgo = HighestBar(High, NBars);
highestPrice = High[highestBarsAgo];
if (highestPrice >= High[0])
{
//Draw.Line(this, "High"+CurrentBar,false,1,high,0,high,Brush es.Silver,DashStyleHelper.Solid,4);
Draw.Line(this, "High"+CurrentBar, false,NBars , 1000, 0, 1001, Brushes.LimeGreen, DashStyleHelper.Dot, 2);
}
lowestBarsAgo = LowestBar(Low, NBars);
lowestPrice = Low[lowestBarsAgo];
if (lowestPrice <= Low[0])
{
//Draw.Line(this, "High"+CurrentBar,false,1,high,0,high,Brush es.Silver,DashStyleHelper.Solid,4);
Draw.Line(this, "Low"+CurrentBar, false,NBars , 1000, 0, 1001, Brushes.Red, DashStyleHelper.Dot, 2);
}
}
Comment