I'm trying to develop an Indicator that Plots Volume but changes color at certain Level same with the bars.
The thing is that I have cut bits of code from here and there and I would like to make it work right. Its actually working (I don't know how ) but I cant change the color as wish. So maybe someone can help me to find out what I am doing wrong in the code ( Im newbie) .
#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 LeoColorVolume : Indicator { protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "LeoColorVolume"; BarsRequiredToPlot = 0; Calculate = Calculate.OnEachTick; DrawOnPricePanel = false; IsSuspendedWhileInactive = true; AddPlot(new Stroke(Brushes.DodgerBlue, 2), PlotStyle.Bar, Custom.Resource.VOLVolume); AddLine(Brushes.DarkGray, 0, Custom.Resource.NinjaScriptIndicatorZeroLine); Calculate = Calculate.OnBarClose; IsOverlay = true; MyVolume = 1000; } else if (State == State.Historical) { if (Calculate == Calculate.OnPriceChange) { Draw.TextFixed(this, "NinjaScriptInfo", string.Format(Custom.Resource.NinjaScriptOnPriceChangeError, Name), TextPosition.BottomRight); Log(string.Format(Custom.Resource.NinjaScriptOnPriceChangeError, Name), LogLevel.Error); } } } protected override void OnBarUpdate() { //Add your custom indicator logic here. if (Volume[0] >= MyVolume) BarBrush = Brushes.Fuchsia; PlotBrushes[0][0] = Brushes.DodgerBlue; if (Volume[0] >= MyVolume) PlotBrushes[0][0] = Brushes.Fuchsia; Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0]; } [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name = "My Volume", GroupName = "NinjaScriptParameters", Order = 0)] public int MyVolume { get; set; } } } #region NinjaScript generated code. Neither change nor remove. namespace NinjaTrader.NinjaScript.Indicators { public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase { private LeoColorVolume[] cacheLeoColorVolume; public LeoColorVolume LeoColorVolume(int myVolume) { return LeoColorVolume(Input, myVolume); } public LeoColorVolume LeoColorVolume(ISeries<double> input, int myVolume) { if (cacheLeoColorVolume != null) for (int idx = 0; idx < cacheLeoColorVolume.Length; idx++) if (cacheLeoColorVolume[idx] != null && cacheLeoColorVolume[idx].MyVolume == myVolume && cacheLeoColorVolume[idx].EqualsInput(input)) return cacheLeoColorVolume[idx]; return CacheIndicator<LeoColorVolume>(new LeoColorVolume(){ MyVolume = myVolume }, input, ref cacheLeoColorVolume); } } } namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns { public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase { public Indicators.LeoColorVolume LeoColorVolume(int myVolume) { return indicator.LeoColorVolume(Input, myVolume); } public Indicators.LeoColorVolume LeoColorVolume(ISeries<double> input , int myVolume) { return indicator.LeoColorVolume(input, myVolume); } } } namespace NinjaTrader.NinjaScript.Strategies { public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase { public Indicators.LeoColorVolume LeoColorVolume(int myVolume) { return indicator.LeoColorVolume(Input, myVolume); } public Indicators.LeoColorVolume LeoColorVolume(ISeries<double> input , int myVolume) { return indicator.LeoColorVolume(input, myVolume); } } } #endregion
Comment