#region Using declarations using System; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.ComponentModel; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; #endregion // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { /// /// RSI con Bandas de Bollinger /// [Description("RSI con Bandas de Bollinger")] public class ZiRSIBollinger : Indicator { #region Variables // Wizard generated variables private int perioRSI = 48; // Default setting for PerioRSI private int perioBB = 89; // Default setting for PerioBB private int desviacion = 2; // Default setting for Desviacion private Color borderColor = Color.Thistle; private Color fillColor = Color.Thistle; private int opacityColor = 2; private bool withColor = true; #endregion /// /// This method is used to configure the indicator and is called once before any bar data is loaded. /// protected override void Initialize() { Add(new Plot(Color.FromKnownColor(KnownColor.Blue), PlotStyle.Line, "RSI")); Add(new Plot(Color.FromKnownColor(KnownColor.LightSteelBlue), PlotStyle.Line, "IndBBsup")); Add(new Plot(Color.FromKnownColor(KnownColor.LightSteelBlue), PlotStyle.Line, "IndBBinf")); Add(new Plot(Color.FromKnownColor(KnownColor.LightSteelBlue), PlotStyle.Line, "IndBBmed")); Add(new Line(Color.Gray, 65, "Upper")); Add(new Line(Color.Gray, 35, "Lower")); Add(new Line(Color.Red, 50, "Banda50")); CalculateOnBarClose = false; Overlay = false; PriceTypeSupported = false; } /// /// Called on each bar update event (incoming tick) /// protected override void OnBarUpdate() { IndRSI.Set(RSI(perioRSI,1)[0]); IndBBmed.Set(SMA(RSI(perioRSI,1),perioBB)[0]); if ( withColor ){ DrawOnPricePanel = false; DrawRegion("Bollinger Region", CurrentBar, 0, Bollinger(RSI(perioRSI,1),desviacion, perioBB).Upper, Bollinger(RSI(perioRSI,1),desviacion, perioBB).Lower, borderColor, fillColor, opacityColor ); } else{ IndBBsup.Set(Bollinger(RSI(perioRSI,1),desviacion,perioBB).Upper[0]); IndBBinf.Set(Bollinger(RSI(perioRSI,1),desviacion,perioBB).Lower[0]); } } #region Properties [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries IndRSI { get { return Values[0]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries IndBBsup { get { return Values[1]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries IndBBinf { get { return Values[2]; } } [Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove public DataSeries IndBBmed { get { return Values[3]; } } [Description("Período RSI")] [Category("Parameters")] public int PerioRSI { get { return perioRSI; } set { perioRSI = Math.Max(1, value); } } [Description("Período Bandas de Bollinger")] [Category("Parameters")] public int PerioBB { get { return perioBB; } set { perioBB = Math.Max(1, value); } } [Description("Desviación")] [Category("Parameters")] public int Desviacion { get { return desviacion; } set { desviacion = Math.Max(1, value); } } [Description("Colorear región BB")] [Category("Parameters")] public bool WithColor { get { return withColor; } set { withColor = value; } } [Description("Opacidad color")] [Category("Parameters")] public int OpacityColor { get { return opacityColor; } set { opacityColor = Math.Max(1, value); } } // Create our user definable color input [Description("Color for painted region")] [Category("Parameters")] public Color BorderColor { get { return borderColor; } set { borderColor = value; } } [Browsable(false)] public string BorderColorSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(borderColor); } set { borderColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } [Description("Color for painted region")] [Category("Parameters")] public Color FillColor { get { return fillColor; } set { fillColor = value; } } [Browsable(false)] public string FillColorSerialize { get { return NinjaTrader.Gui.Design.SerializableColor.ToString(fillColor); } set { fillColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); } } #endregion } } #region NinjaScript generated code. Neither change nor remove. // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator { public partial class Indicator : IndicatorBase { private ZiRSIBollinger[] cacheZiRSIBollinger = null; private static ZiRSIBollinger checkZiRSIBollinger = new ZiRSIBollinger(); /// /// RSI con Bandas de Bollinger /// /// public ZiRSIBollinger ZiRSIBollinger(Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { return ZiRSIBollinger(Input, borderColor, desviacion, fillColor, opacityColor, perioBB, perioRSI, withColor); } /// /// RSI con Bandas de Bollinger /// /// public ZiRSIBollinger ZiRSIBollinger(Data.IDataSeries input, Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { checkZiRSIBollinger.BorderColor = borderColor; borderColor = checkZiRSIBollinger.BorderColor; checkZiRSIBollinger.Desviacion = desviacion; desviacion = checkZiRSIBollinger.Desviacion; checkZiRSIBollinger.FillColor = fillColor; fillColor = checkZiRSIBollinger.FillColor; checkZiRSIBollinger.OpacityColor = opacityColor; opacityColor = checkZiRSIBollinger.OpacityColor; checkZiRSIBollinger.PerioBB = perioBB; perioBB = checkZiRSIBollinger.PerioBB; checkZiRSIBollinger.PerioRSI = perioRSI; perioRSI = checkZiRSIBollinger.PerioRSI; checkZiRSIBollinger.WithColor = withColor; withColor = checkZiRSIBollinger.WithColor; if (cacheZiRSIBollinger != null) for (int idx = 0; idx < cacheZiRSIBollinger.Length; idx++) if (cacheZiRSIBollinger[idx].BorderColor == borderColor && cacheZiRSIBollinger[idx].Desviacion == desviacion && cacheZiRSIBollinger[idx].FillColor == fillColor && cacheZiRSIBollinger[idx].OpacityColor == opacityColor && cacheZiRSIBollinger[idx].PerioBB == perioBB && cacheZiRSIBollinger[idx].PerioRSI == perioRSI && cacheZiRSIBollinger[idx].WithColor == withColor && cacheZiRSIBollinger[idx].EqualsInput(input)) return cacheZiRSIBollinger[idx]; ZiRSIBollinger indicator = new ZiRSIBollinger(); indicator.BarsRequired = BarsRequired; indicator.CalculateOnBarClose = CalculateOnBarClose; indicator.Input = input; indicator.BorderColor = borderColor; indicator.Desviacion = desviacion; indicator.FillColor = fillColor; indicator.OpacityColor = opacityColor; indicator.PerioBB = perioBB; indicator.PerioRSI = perioRSI; indicator.WithColor = withColor; indicator.SetUp(); ZiRSIBollinger[] tmp = new ZiRSIBollinger[cacheZiRSIBollinger == null ? 1 : cacheZiRSIBollinger.Length + 1]; if (cacheZiRSIBollinger != null) cacheZiRSIBollinger.CopyTo(tmp, 0); tmp[tmp.Length - 1] = indicator; cacheZiRSIBollinger = tmp; Indicators.Add(indicator); return indicator; } } } // This namespace holds all market analyzer column definitions and is required. Do not change it. namespace NinjaTrader.MarketAnalyzer { public partial class Column : ColumnBase { /// /// RSI con Bandas de Bollinger /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.ZiRSIBollinger ZiRSIBollinger(Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { return _indicator.ZiRSIBollinger(Input, borderColor, desviacion, fillColor, opacityColor, perioBB, perioRSI, withColor); } /// /// RSI con Bandas de Bollinger /// /// public Indicator.ZiRSIBollinger ZiRSIBollinger(Data.IDataSeries input, Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { return _indicator.ZiRSIBollinger(input, borderColor, desviacion, fillColor, opacityColor, perioBB, perioRSI, withColor); } } } // This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { public partial class Strategy : StrategyBase { /// /// RSI con Bandas de Bollinger /// /// [Gui.Design.WizardCondition("Indicator")] public Indicator.ZiRSIBollinger ZiRSIBollinger(Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { return _indicator.ZiRSIBollinger(Input, borderColor, desviacion, fillColor, opacityColor, perioBB, perioRSI, withColor); } /// /// RSI con Bandas de Bollinger /// /// public Indicator.ZiRSIBollinger ZiRSIBollinger(Data.IDataSeries input, Color borderColor, int desviacion, Color fillColor, int opacityColor, int perioBB, int perioRSI, bool withColor) { if (InInitialize && input == null) throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method"); return _indicator.ZiRSIBollinger(input, borderColor, desviacion, fillColor, opacityColor, perioBB, perioRSI, withColor); } } } #endregion