144 lines
4.7 KiB
C#
144 lines
4.7 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Gui;
|
|
using NinjaTrader.Gui.Chart;
|
|
using System.ComponentModel;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Windows.Media;
|
|
using System.Xml.Serialization;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
[CategoryOrder("Chandelier Exit", 1)]
|
|
[CategoryOrder("Plots", 2)]
|
|
public class ChandelierExit : Indicator
|
|
{
|
|
private ATR atr;
|
|
private MAX highestHigh;
|
|
private MIN lowestLow;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Chandelier Exit Indicator";
|
|
Name = "Chandelier Exit";
|
|
Calculate = Calculate.OnBarClose;
|
|
IsOverlay = true;
|
|
DisplayInDataBox = true;
|
|
DrawOnPricePanel = true;
|
|
PaintPriceMarkers = true;
|
|
ScaleJustification = ScaleJustification.Right;
|
|
IsSuspendedWhileInactive = true;
|
|
|
|
Period = 22;
|
|
ATRMultiplier = 3.0;
|
|
|
|
AddPlot(new Stroke(Brushes.LimeGreen, DashStyleHelper.Solid, 3), PlotStyle.Line, "Long Exit");
|
|
AddPlot(new Stroke(Brushes.Red, DashStyleHelper.Solid, 3), PlotStyle.Line, "Short Exit");
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
atr = ATR(Period);
|
|
highestHigh = MAX(High, Period);
|
|
lowestLow = MIN(Low, Period);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < Period)
|
|
return;
|
|
|
|
LongExit[0] = highestHigh[0] - atr[0] * ATRMultiplier;
|
|
ShortExit[0] = lowestLow[0] + atr[0] * ATRMultiplier;
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[Browsable(false)]
|
|
[XmlIgnore]
|
|
public Series<double> LongExit
|
|
{
|
|
get { return Values[0]; }
|
|
}
|
|
|
|
[Browsable(false)]
|
|
[XmlIgnore]
|
|
public Series<double> ShortExit
|
|
{
|
|
get { return Values[1]; }
|
|
}
|
|
|
|
[Range(1, int.MaxValue), NinjaScriptProperty]
|
|
[Display(Name = "Period", GroupName = "Chandelier Exit", Order = 1)]
|
|
public int Period
|
|
{ get; set; }
|
|
|
|
[Range(0.1, double.MaxValue), NinjaScriptProperty]
|
|
[Display(Name = "ATR Multiplier", GroupName = "Chandelier Exit", Order = 2)]
|
|
public double ATRMultiplier
|
|
{ get; set; }
|
|
}
|
|
}
|
|
|
|
#region NinjaScript generated code. Neither change nor remove.
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
|
{
|
|
private ChandelierExit[] cacheChandelierExit;
|
|
public ChandelierExit ChandelierExit(int period, double aTRMultiplier)
|
|
{
|
|
return ChandelierExit(Input, period, aTRMultiplier);
|
|
}
|
|
|
|
public ChandelierExit ChandelierExit(ISeries<double> input, int period, double aTRMultiplier)
|
|
{
|
|
if (cacheChandelierExit != null)
|
|
for (int idx = 0; idx < cacheChandelierExit.Length; idx++)
|
|
if (cacheChandelierExit[idx] != null && cacheChandelierExit[idx].Period == period && cacheChandelierExit[idx].ATRMultiplier == aTRMultiplier && cacheChandelierExit[idx].EqualsInput(input))
|
|
return cacheChandelierExit[idx];
|
|
return CacheIndicator<ChandelierExit>(new ChandelierExit(){ Period = period, ATRMultiplier = aTRMultiplier }, input, ref cacheChandelierExit);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
|
{
|
|
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
|
{
|
|
public Indicators.ChandelierExit ChandelierExit(int period, double aTRMultiplier)
|
|
{
|
|
return indicator.ChandelierExit(Input, period, aTRMultiplier);
|
|
}
|
|
|
|
public Indicators.ChandelierExit ChandelierExit(ISeries<double> input , int period, double aTRMultiplier)
|
|
{
|
|
return indicator.ChandelierExit(input, period, aTRMultiplier);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
|
{
|
|
public Indicators.ChandelierExit ChandelierExit(int period, double aTRMultiplier)
|
|
{
|
|
return indicator.ChandelierExit(Input, period, aTRMultiplier);
|
|
}
|
|
|
|
public Indicators.ChandelierExit ChandelierExit(ISeries<double> input , int period, double aTRMultiplier)
|
|
{
|
|
return indicator.ChandelierExit(input, period, aTRMultiplier);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|