I know I'm doing something wrong syntaxwise, but I'm also not sure how to frame the properties for D and K so that I can plot them
Thanks in advance.
D
#region Using declarations using System; using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Input; using System.Windows.Media; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Gui; using NinjaTrader.Gui.Chart; using NinjaTrader.Gui.SuperDom; using NinjaTrader.Gui.Tools; using NinjaTrader.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion //This namespace holds indicators in this folder and is required. Do not change it. namespace NinjaTrader.NinjaScript.Indicators { /* The StoRSI is an oscillator similar in computation to the stochastic measure, except instead of price values as input, the StoRSI uses RSI values. The StoRSI computes the current position of the RSI relative to the high and low RSI values over a specified number of days. The intent of this measure, designed by Tushard Chande and Stanley Kroll, is to provide further information about the overbought/oversold nature of the RSI. The StoRSI ranges between 0.0 and 1.0. Values above 0.8 are generally seen to identify overbought levels and values below 0.2 are considered to indicate oversold conditions. */ public class Lynx_StoRSI : Indicator { private MAX max; private MIN min; private RSI rsi; public Series<double> D; public Series<double> K; #region Variables private int periodRSI = 13; private int periodD = 13; private int periodK = 8; #endregion public override string DisplayName { get { return "Lynx Stochastic RSI"; } ///PREVENTS SHOWING ALL PARAMETERS AT THE TOP OF THE INDICATOR } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"The Lynx StoRSI is an oscillator similar in computation to the stochastic measure, except instead of price values as input, the LynxStoRSI uses RSI values. The LynxStoRSI computes the current position of the RSI relative to the high and low RSI values over a specified number of days. The intent of this measure, designed by Tushard Chande and Stanley Kroll, is to provide further information about the overbought/oversold nature of the RSI. The LynxStoRSI ranges between 0.0 and 1.0. Values above 0.8 are generally seen to identify overbought levels and values below 0.2 are considered to indicate oversold conditions."; Name = "Lynx Stochastic RSI"; IsSuspendedWhileInactive = true; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = false; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; AddPlot(Brushes.Red, "D"); AddPlot(Brushes.Cyan, "K"); AddLine(Brushes.Red, 0.8, "Overbought"); AddLine(Brushes.Blue, 0.5, "Neutral"); AddLine(Brushes.Red, 0.2, "Oversold"); } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> else if (State == State.DataLoaded) { rsi = RSI(Inputs[0], PeriodRSI, 1)[0]; rsiL = MIN(RSI(Inputs[0], PeriodRSI, 1), PeriodD[0]); rsiH = MAX(RSI(Inputs[0], PeriodRSI, 1), PeriodD[0]); if (rsi != rsiL && rsiH != rsiL) K.Set((rsi - rsiL) / (rsiH - rsiL)); else K.Set(0); D.Set(SMA(K, PeriodK)[0]); } } //----------------------------------- #region Properties /// <summary> /// Gets the slow D value. /// </summary> [Browsable(false)] [XmlIgnore()] public Series D { get { return Values[0]; } } //----------------------------------- /// <summary> /// Gets the slow K value. /// </summary> [Browsable(false)] [XmlIgnore()] public Series K { get { return Values[1]; } } //----------------------------------- /// <summary> /// </summary> [Description("Numbers of bars used for moving average over K values")] [Display(Name = "Period for RSI", Order = 1, GroupName = "My Parameters")] int PeriodRSI { get { return periodRSI; } set { periodRSI = Math.Max(1, value); } } //----------------------------------- /// <summary> /// </summary> [Description("Numbers of bars used for moving average over K values")] [Display(Name = "Period for D", Order = 1, GroupName = "My Parameters")] public int PeriodD { get { return periodD; } set { periodD = Math.Max(1, value); } } //----------------------------------- /// <summary> /// </summary> [Description("Numbers of bars used for calculating the K values")] [Display(Name = "Period for K", Order = 1, GroupName = "My Parameters")] public int PeriodK { get { return periodK; } set { periodK = Math.Max(1, value); } } #endregion } }
Comment