134 lines
4.9 KiB
C#
134 lines
4.9 KiB
C#
#region Using declarations
|
|
using NinjaTrader.Gui;
|
|
using NinjaTrader.Gui.Chart;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Windows.Media;
|
|
#endregion
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
[CategoryOrder("Cumulative RSI", 1)]
|
|
[CategoryOrder("Plots", 2)]
|
|
public class CumulativeRSI : Indicator
|
|
{
|
|
private RSI rsi;
|
|
|
|
protected override void OnStateChange()
|
|
{
|
|
if (State == State.SetDefaults)
|
|
{
|
|
Description = @"Credit to Larry Connors and his book Short Term Trading Strategies That Work";
|
|
Name = "Cumulative RSI";
|
|
Calculate = Calculate.OnPriceChange;
|
|
IsOverlay = false;
|
|
DisplayInDataBox = true;
|
|
DrawOnPricePanel = true;
|
|
PaintPriceMarkers = true;
|
|
ScaleJustification = ScaleJustification.Right;
|
|
IsSuspendedWhileInactive = true;
|
|
|
|
AddPlot(new Stroke(Brushes.Yellow, DashStyleHelper.Solid, 3), PlotStyle.Line, "Cumulative RSI");
|
|
|
|
RSIPeriod = 2;
|
|
RSISmoothing = 1;
|
|
CumulativePeriod = 2;
|
|
}
|
|
else if (State == State.DataLoaded)
|
|
{
|
|
rsi = RSI(RSIPeriod, RSISmoothing);
|
|
}
|
|
}
|
|
|
|
protected override void OnBarUpdate()
|
|
{
|
|
if (CurrentBar < CumulativePeriod)
|
|
return;
|
|
|
|
double cumulativeRSI = 0;
|
|
for (int i = 0; i < CumulativePeriod; i++)
|
|
cumulativeRSI += rsi[i];
|
|
|
|
Value[0] = cumulativeRSI;
|
|
}
|
|
|
|
public override string DisplayName
|
|
{
|
|
get { return Name; }
|
|
}
|
|
|
|
#region Properties
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "RSI Period", Description = "The period for the RSI calculation", GroupName = "Cumulative RSI", Order = 1)]
|
|
public int RSIPeriod { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "RSI Smoothing", Description = "The smoothing used for the RSI calculation", GroupName = "Cumulative RSI", Order = 2)]
|
|
public int RSISmoothing { get; set; }
|
|
|
|
[NinjaScriptProperty]
|
|
[Range(1, int.MaxValue)]
|
|
[Display(Name = "Cumulative Period", Description = "The number of RSI values to add together", GroupName = "Cumulative RSI", Order = 3)]
|
|
public int CumulativePeriod { get; set; }
|
|
#endregion
|
|
}
|
|
}
|
|
|
|
#region NinjaScript generated code. Neither change nor remove.
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
{
|
|
public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
|
|
{
|
|
private CumulativeRSI[] cacheCumulativeRSI;
|
|
public CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
return CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
|
}
|
|
|
|
public CumulativeRSI CumulativeRSI(ISeries<double> input, int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
if (cacheCumulativeRSI != null)
|
|
for (int idx = 0; idx < cacheCumulativeRSI.Length; idx++)
|
|
if (cacheCumulativeRSI[idx] != null && cacheCumulativeRSI[idx].RSIPeriod == rSIPeriod && cacheCumulativeRSI[idx].RSISmoothing == rSISmoothing && cacheCumulativeRSI[idx].CumulativePeriod == cumulativePeriod && cacheCumulativeRSI[idx].EqualsInput(input))
|
|
return cacheCumulativeRSI[idx];
|
|
return CacheIndicator<CumulativeRSI>(new CumulativeRSI(){ RSIPeriod = rSIPeriod, RSISmoothing = rSISmoothing, CumulativePeriod = cumulativePeriod }, input, ref cacheCumulativeRSI);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
|
{
|
|
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
|
{
|
|
public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
return indicator.CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
|
}
|
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(ISeries<double> input , int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
return indicator.CumulativeRSI(input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
|
}
|
|
}
|
|
}
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
{
|
|
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
|
{
|
|
public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
return indicator.CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
|
}
|
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(ISeries<double> input , int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
|
{
|
|
return indicator.CumulativeRSI(input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
|
}
|
|
}
|
|
}
|
|
|
|
#endregion
|