128 lines
3.9 KiB
C#
128 lines
3.9 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Gui;
|
|
using NinjaTrader.Gui.Chart;
|
|
using System;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Windows.Media;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public class EfficiencyRatio : Indicator
|
|
{
|
|
private SUM sumOfPriceChanges;
|
|
|
|
private Series<double> priceChanges;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Kaufman Efficiency Ratio";
|
|
Name = "Efficiency Ratio";
|
|
Calculate = Calculate.OnBarClose;
|
|
IsOverlay = false;
|
|
DisplayInDataBox = true;
|
|
DrawOnPricePanel = true;
|
|
DrawHorizontalGridLines = true;
|
|
DrawVerticalGridLines = true;
|
|
PaintPriceMarkers = true;
|
|
ScaleJustification = ScaleJustification.Right;
|
|
IsSuspendedWhileInactive = true;
|
|
|
|
Period = 10;
|
|
|
|
AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 2), PlotStyle.Line, "Efficiency Ratio");
|
|
}
|
|
else if (State == State.Configure)
|
|
{
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
priceChanges = new Series<double>(this, MaximumBarsLookBack.Infinite);
|
|
|
|
sumOfPriceChanges = SUM(priceChanges, Period);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < 1)
|
|
return;
|
|
|
|
priceChanges[0] = Math.Abs(Close[0] - Close[1]);
|
|
|
|
if (CurrentBar < Period)
|
|
Value[0] = 0.0;
|
|
else
|
|
Value[0] = Math.Abs(Close[0] - Close[Period]) / sumOfPriceChanges[0];
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
[Range(1, int.MaxValue), NinjaScriptProperty]
|
|
[Display(Name = "Period", GroupName = "Efficiency Ratio", Order = 1)]
|
|
public int Period { get; set; }
|
|
}
|
|
}
|
|
|
|
#region NinjaScript generated code. Neither change nor remove.
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
|
{
|
|
private EfficiencyRatio[] cacheEfficiencyRatio;
|
|
public EfficiencyRatio EfficiencyRatio(int period)
|
|
{
|
|
return EfficiencyRatio(Input, period);
|
|
}
|
|
|
|
public EfficiencyRatio EfficiencyRatio(ISeries<double> input, int period)
|
|
{
|
|
if (cacheEfficiencyRatio != null)
|
|
for (int idx = 0; idx < cacheEfficiencyRatio.Length; idx++)
|
|
if (cacheEfficiencyRatio[idx] != null && cacheEfficiencyRatio[idx].Period == period && cacheEfficiencyRatio[idx].EqualsInput(input))
|
|
return cacheEfficiencyRatio[idx];
|
|
return CacheIndicator<EfficiencyRatio>(new EfficiencyRatio(){ Period = period }, input, ref cacheEfficiencyRatio);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
|
{
|
|
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
|
{
|
|
public Indicators.EfficiencyRatio EfficiencyRatio(int period)
|
|
{
|
|
return indicator.EfficiencyRatio(Input, period);
|
|
}
|
|
|
|
public Indicators.EfficiencyRatio EfficiencyRatio(ISeries<double> input , int period)
|
|
{
|
|
return indicator.EfficiencyRatio(input, period);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
|
{
|
|
public Indicators.EfficiencyRatio EfficiencyRatio(int period)
|
|
{
|
|
return indicator.EfficiencyRatio(Input, period);
|
|
}
|
|
|
|
public Indicators.EfficiencyRatio EfficiencyRatio(ISeries<double> input , int period)
|
|
{
|
|
return indicator.EfficiencyRatio(input, period);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|