Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Help to Draw a rectangle

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

    Help to Draw a rectangle

    Hi, I was able to make my custom indcator ( code below ), now I´m trying also to draw rectangles in the candles wicks based in the volume conditions in the code but no way.

    Code:
    //
    // Copyright (C) 2019, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    #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.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
    {
        /// <summary>
        /// Volume is simply the number of shares (or contracts) traded during a specified time frame (e.g. hour, day, week, month, etc).
        /// </summary>
        public class VolLoBo : Indicator
        {
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                    = Custom.Resource.NinjaScriptIndicatorDescriptionVOL;
                    Name                        = "VolLoBo";
                    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);
                    VolRelev1                        = 100;  // added
                    ColorVolRel1                = Brushes.Green; // added
                    VolRelev2                        = 200;  // added
                    ColorVolRel2                = Brushes.Red; // added
                }
                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()
            {
                Value[0] = Instrument.MasterInstrument.InstrumentType == InstrumentType.CryptoCurrency ? Core.Globals.ToCryptocurrencyVolume((long)Volume[0]) : Volume[0];
    
                if (Value[0] >= VolRelev1)                 // added
                {
                    PlotBrushes[0][0] = ColorVolRel1;  // added
                }
    
                if (Value[0] >= VolRelev2)                 // added
                {
                    PlotBrushes[0][0] = ColorVolRel2;  // added
                }
    
            }
    
            [NinjaScriptProperty]  // added
            [Range(1, int.MaxValue)]
            [Display(Name="Volumen Relevante", Description="Set the trigger level for color change", Order=1, GroupName="Detection")]
            public int VolRelev1
            { get; set; }
    
            [Display(Name="Super Volumen", Description="Set the trigger level for color change", Order=3, GroupName="Detection")]
            public int VolRelev2
            { get; set; }
    
            [Display(Name="Color V. Relevante", Description="Color of the triggered volume", Order=2, GroupName="Detection")]
            public Brush ColorVolRel1
            { get; set; }
    
            [Browsable(false)]
            public string  ColorVolRel1Serializable
            {
                get { return Serialize.BrushToString(ColorVolRel1); }
                set { ColorVolRel1 = Serialize.StringToBrush(value); }
            }
    
            [Display(Name="Color Super Volumen", Description="Color of the triggered volume", Order=4, GroupName="Detection")]
            public Brush ColorVolRel2
            { get; set; }
    
            [Browsable(false)]
            public string  ColorVolRel2Serializable
            {
                get { return Serialize.BrushToString(ColorVolRel2); }
                set { ColorVolRel2 = Serialize.StringToBrush(value); }
            }
    
        }
    }
    
    #region NinjaScript generated code. Neither change nor remove.
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public partial class Indicator : NinjaTrader.Gui.NinjaScript.IndicatorRenderBase
        {
            private VolLoBo[] cacheVolLoBo;
            public VolLoBo VolLoBo(int volRelev1)
            {
                return VolLoBo(Input, volRelev1);
            }
    
            public VolLoBo VolLoBo(ISeries<double> input, int volRelev1)
            {
                if (cacheVolLoBo != null)
                    for (int idx = 0; idx < cacheVolLoBo.Length; idx++)
                        if (cacheVolLoBo[idx] != null && cacheVolLoBo[idx].VolRelev1 == volRelev1 && cacheVolLoBo[idx].EqualsInput(input))
                            return cacheVolLoBo[idx];
                return CacheIndicator<VolLoBo>(new VolLoBo(){ VolRelev1 = volRelev1 }, input, ref cacheVolLoBo);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.MarketAnalyzerColumns
    {
        public partial class MarketAnalyzerColumn : MarketAnalyzerColumnBase
        {
            public Indicators.VolLoBo VolLoBo(int volRelev1)
            {
                return indicator.VolLoBo(Input, volRelev1);
            }
    
            public Indicators.VolLoBo VolLoBo(ISeries<double> input , int volRelev1)
            {
                return indicator.VolLoBo(input, volRelev1);
            }
        }
    }
    
    namespace NinjaTrader.NinjaScript.Strategies
    {
        public partial class Strategy : NinjaTrader.Gui.NinjaScript.StrategyRenderBase
        {
            public Indicators.VolLoBo VolLoBo(int volRelev1)
            {
                return indicator.VolLoBo(Input, volRelev1);
            }
    
            public Indicators.VolLoBo VolLoBo(ISeries<double> input , int volRelev1)
            {
                return indicator.VolLoBo(input, volRelev1);
            }
        }
    }
    
    #endregion
    What I'm trying to do is like this:

    Click image for larger version

Name:	Captura.JPG
Views:	1627
Size:	95.6 KB
ID:	1049310


    As in the picture I'm trying to draw rectangles in candle wicks where volume bars (in green) have the variable conditions, in ther red candle the rectangle will be in lowest and close price, and in the green candle the rectangle will be in the highest and close price.

    Thanks in advance.

    #2
    Hello superg3,

    Thanks for your post.

    To draw rectangles you would need to use the Draw.Rectangle() method. In the Draw.Rectangle() method you would use the method overload that allows you to specify the start bars ago, the end bars ago, the High and the Low of the rectangle to draw, here is a link to the help guide section: https://ninjatrader.com/support/help..._rectangle.htm



    Comment


      #3
      Originally posted by NinjaTrader_PaulH View Post
      Hello superg3,

      Thanks for your post.

      To draw rectangles you would need to use the Draw.Rectangle() method. In the Draw.Rectangle() method you would use the method overload that allows you to specify the start bars ago, the end bars ago, the High and the Low of the rectangle to draw, here is a link to the help guide section: https://ninjatrader.com/support/help..._rectangle.htm


      Hello PaulH, I'm trying but no way. I'm using the method Draw.Rectangle(NinjaScriptBaseowner,stringtag,intstartBarsAgo,doublestartY,intendBarsAgo,doubleendY,Brushbrush);
      I have some problems here, I do not know how asign to startY the candle Higher price and to endY the candle close price.
      Also I need to draw the rectangles in real time from the candle's wick that just closed to the right side where there is no candles yet.

      Comment


        #4
        Hello superg3,

        Thanks for your reply.

        Here is an example that helps you to see how to draw into the future:

        Draw.Rectangle(this, "tag1", 0, Low[0] - TickSize, -5, High[0] + TickSize, Brushes.Blue);

        The -5 would be 5 bars into the future, the Low[0] - TickSize and High[0]+Ticksize are using the current bar's high and low to size the rectangle, 0 is the start bar which is the current bar.

        Here is what that looks like on a chart.

        Click image for larger version

Name:	superg3-1.PNG
Views:	1564
Size:	27.2 KB
ID:	1049410

        Comment


          #5
          Originally posted by NinjaTrader_PaulH View Post
          Hello superg3,

          Thanks for your reply.

          Here is an example that helps you to see how to draw into the future:

          Draw.Rectangle(this, "tag1", 0, Low[0] - TickSize, -5, High[0] + TickSize, Brushes.Blue);

          The -5 would be 5 bars into the future, the Low[0] - TickSize and High[0]+Ticksize are using the current bar's high and low to size the rectangle, 0 is the start bar which is the current bar.

          Here is what that looks like on a chart.

          Click image for larger version

Name:	superg3-1.PNG
Views:	1564
Size:	27.2 KB
ID:	1049410
          Thats exactly what I want! I added the code but as you can check I´m forgeting something and it doesn´t draw it. Thanks for your patience :-(
          VolLoBo.zip

          Comment


            #6
            Originally posted by superg3 View Post

            Thats exactly what I want! I added the code but as you can check I´m forgeting something and it doesn´t draw it. Thanks for your patience :-(
            [ATTACH]n1049414[/ATTACH]
            Solved with DrawOnPricePanel = true;

            Thank you very much!

            Comment


              #7
              Hi again,

              I just found taht with each new rectangle the previous one is deleted. Please could you tell me how I can preserve previous drawn rectangles?
              Thanks in advance.

              VoLoBo21.zip
              Last edited by superg3; 02-26-2019, 10:06 AM.

              Comment


                #8
                Hello superg3,

                Thanks for your reply.

                Draw objects must have a unique tag name, otherwise, they are replaced by the newer one with the same tag name. A common way to create a unique (per bar) tag name is to add the current bar number to the tag name, for example: Draw.Rectangle(this, "tag1"+CurrentBar, 0, Low[0] - TickSize, -5, High[0] + TickSize, Brushes.Blue);

                Comment


                  #9
                  Originally posted by NinjaTrader_PaulH View Post
                  Hello superg3,

                  Thanks for your reply.

                  Draw objects must have a unique tag name, otherwise, they are replaced by the newer one with the same tag name. A common way to create a unique (per bar) tag name is to add the current bar number to the tag name, for example: Draw.Rectangle(this, "tag1"+CurrentBar, 0, Low[0] - TickSize, -5, High[0] + TickSize, Brushes.Blue);


                  Thank you very much PaulH, it works perfect now!!

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  558 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  324 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  546 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X