#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 { public class CandleColor : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Allows for coloring up / down candle bodies and wicks independently"; Name = "Candle Color"; Calculate = Calculate.OnPriceChange; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = ScaleJustification.Right; IsSuspendedWhileInactive = true; UpCandleColor = Brushes.LimeGreen; DownCandleColor = Brushes.Red; } } protected override void OnBarUpdate() { if (Close[0] > Open[0]) { BarBrushes[0] = UpCandleColor; CandleOutlineBrushes[0] = UpCandleColor; } else if (Close[0] < Open[0]) { BarBrushes[0] = DownCandleColor; CandleOutlineBrushes[0] = DownCandleColor; } else { BarBrushes[0] = BarBrushes[1]; CandleOutlineBrushes[0] = CandleOutlineBrushes[1]; } } public override string DisplayName { get { return Name; } } [NinjaScriptProperty] [XmlIgnore] [Display(Name = "Up Candle", GroupName = "Candle Color", Order = 1)] public Brush UpCandleColor { get; set; } [Browsable(false)] public string UpCandleColorSerialization { get { return Serialize.BrushToString(UpCandleColor); } set { UpCandleColor = Serialize.StringToBrush(value); } } [NinjaScriptProperty] [XmlIgnore] [Display(Name = "Down Candle", GroupName = "Candle Color", Order = 2)] public Brush DownCandleColor { get; set; } [Browsable(false)] public string DownCandleColorSerialization { get { return Serialize.BrushToString(DownCandleColor); } set { DownCandleColor = Serialize.StringToBrush(value); } } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private CandleColor[] cacheCandleColor; public CandleColor CandleColor(Brush upCandleColor, Brush downCandleColor) { return CandleColor(Input, upCandleColor, downCandleColor); } public CandleColor CandleColor(ISeries input, Brush upCandleColor, Brush downCandleColor) { if (cacheCandleColor != null) for (int idx = 0; idx < cacheCandleColor.Length; idx++) if (cacheCandleColor[idx] != null && cacheCandleColor[idx].UpCandleColor == upCandleColor && cacheCandleColor[idx].DownCandleColor == downCandleColor && cacheCandleColor[idx].EqualsInput(input)) return cacheCandleColor[idx]; return CacheIndicator(new CandleColor(){ UpCandleColor = upCandleColor, DownCandleColor = downCandleColor }, input, ref cacheCandleColor); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.CandleColor CandleColor(Brush upCandleColor, Brush downCandleColor) { return indicator.CandleColor(Input, upCandleColor, downCandleColor); } public Indicators.CandleColor CandleColor(ISeries input , Brush upCandleColor, Brush downCandleColor) { return indicator.CandleColor(input, upCandleColor, downCandleColor); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.CandleColor CandleColor(Brush upCandleColor, Brush downCandleColor) { return indicator.CandleColor(Input, upCandleColor, downCandleColor); } public Indicators.CandleColor CandleColor(ISeries input , Brush upCandleColor, Brush downCandleColor) { return indicator.CandleColor(input, upCandleColor, downCandleColor); } } } #endregion