Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Volume Color Bars

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Volume Color Bars

    Hi Everyone,

    I'm trying to develop an Indicator that Plots Volume but changes color at certain Level same with the bars.

    Click image for larger version

Name:	Captura de pantalla 2024-12-12 191938.png
Views:	94
Size:	256.6 KB
ID:	1327599

    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) .

    Code:
    #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
    ​
    Regards / Gracias​


    #2
    Hello Rxxar,

    Thank you for your post.

    Are you trying to change the bar color, or the plot color?

    BarBrush will change the color of the bar.
    PlotBrushes will change the color of the plot.

    It also looks like you have the same exact condition for the color change logic. If you want the color to change, you'll need to have different conditions for the color change logic.

    Please let us know if you have any further questions. ​
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by leunating, Today, 12:56 AM
    2 responses
    17 views
    0 likes
    Last Post leunating  
    Started by tmk-c, 07-19-2017, 11:29 PM
    6 responses
    1,687 views
    0 likes
    Last Post Brightredmegaphone  
    Started by Trader4Life, Today, 09:20 PM
    0 responses
    5 views
    0 likes
    Last Post Trader4Life  
    Started by WileCoyote, Today, 08:26 PM
    0 responses
    8 views
    0 likes
    Last Post WileCoyote  
    Started by madankumars, 11-18-2019, 11:12 AM
    10 responses
    176 views
    0 likes
    Last Post ulisesguerrero  
    Working...
    X