2024-09-10 13:36:17 +00:00
|
|
|
#region Using declarations
|
|
|
|
using NinjaTrader.Gui;
|
|
|
|
using NinjaTrader.Gui.Chart;
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
using System.Windows.Media;
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
namespace NinjaTrader.NinjaScript.Indicators
|
|
|
|
{
|
|
|
|
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;
|
2024-09-10 13:43:45 +00:00
|
|
|
RSISmoothing = 1;
|
2024-09-10 13:36:17 +00:00
|
|
|
CumulativePeriod = 2;
|
|
|
|
}
|
|
|
|
else if (State == State.DataLoaded)
|
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
rsi = RSI(RSIPeriod, RSISmoothing);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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", Order = 1, GroupName = "Cumulative RSI")]
|
|
|
|
public int RSIPeriod { get; set; }
|
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Range(1, int.MaxValue)]
|
2024-09-10 13:43:45 +00:00
|
|
|
[Display(Name = "RSI Smoothing", Description = "The smoothing used for the RSI calculation", Order = 2, GroupName = "Cumulative RSI")]
|
|
|
|
public int RSISmoothing { get; set; }
|
|
|
|
|
|
|
|
[NinjaScriptProperty]
|
|
|
|
[Range(1, int.MaxValue)]
|
|
|
|
[Display(Name = "Cumulative Period", Description = "The number of RSI values to add together", Order = 3, GroupName = "Cumulative RSI")]
|
2024-09-10 13:36:17 +00:00
|
|
|
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;
|
2024-09-10 13:43:45 +00:00
|
|
|
public CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
return CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 13:43:45 +00:00
|
|
|
public CumulativeRSI CumulativeRSI(ISeries<double> input, int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
|
|
|
if (cacheCumulativeRSI != null)
|
|
|
|
for (int idx = 0; idx < cacheCumulativeRSI.Length; idx++)
|
2024-09-10 13:43:45 +00:00
|
|
|
if (cacheCumulativeRSI[idx] != null && cacheCumulativeRSI[idx].RSIPeriod == rSIPeriod && cacheCumulativeRSI[idx].RSISmoothing == rSISmoothing && cacheCumulativeRSI[idx].CumulativePeriod == cumulativePeriod && cacheCumulativeRSI[idx].EqualsInput(input))
|
2024-09-10 13:36:17 +00:00
|
|
|
return cacheCumulativeRSI[idx];
|
2024-09-10 13:43:45 +00:00
|
|
|
return CacheIndicator<CumulativeRSI>(new CumulativeRSI(){ RSIPeriod = rSIPeriod, RSISmoothing = rSISmoothing, CumulativePeriod = cumulativePeriod }, input, ref cacheCumulativeRSI);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
|
|
|
|
{
|
|
|
|
public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
|
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
return indicator.CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 13:43:45 +00:00
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(ISeries<double> input , int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
return indicator.CumulativeRSI(input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace NinjaTrader.NinjaScript.Strategies
|
|
|
|
{
|
|
|
|
public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
|
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
return indicator.CumulativeRSI(Input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
|
2024-09-10 13:43:45 +00:00
|
|
|
public Indicators.CumulativeRSI CumulativeRSI(ISeries<double> input , int rSIPeriod, int rSISmoothing, int cumulativePeriod)
|
2024-09-10 13:36:17 +00:00
|
|
|
{
|
2024-09-10 13:43:45 +00:00
|
|
|
return indicator.CumulativeRSI(input, rSIPeriod, rSISmoothing, cumulativePeriod);
|
2024-09-10 13:36:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|