Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Change the wick color of the candles

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

    Change the wick color of the candles

    Hi everyone,
    someone know which code lines i need to add in that script to also be able to change the wick colour of the candles?

    [url]https://ninjatraderecosystem.com/user-app-share-download/candlesticks-chartstyle-with-outline-opacity/[/url]

    #2
    Hello rafaelcoisa,

    Thanks for your post.

    CandleOutlineBrush would be used to change the color of the candle's border and wicks.

    See the help guide page below for more information.

    CandleOutlineBrush: [url]https://ninjatrader.com/support/helpGuides/nt8/candleoutlinebrush.htm[/url]

    Also, see the attached example script which demonstrates using CandleOutlineBrush.

    Let us know if we may assist further.
    Attached Files
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      This is a very old and frequent request (possibility of full customization of the candles). The solution is already out there. I'll wait for someone to share it with me. But thanks for the indication. If the solution does not come, I will take a close look to this file. For now, I don't have time to learn C#.

      Comment


        #4
        I found the file below. with it I can change the colours of the bodies and wicks. has the possibility to modify the borders, but it doesn't work. how to make it work? Anybody know?
        Attached Files

        Comment


          #5
          Hello rafaelcoisa,
          Please refer below link, I've shared candle style for wick color as body color.
          [URL]https://ninjatrader.com/support/forum/forum/ninjatrader-8/platform-technical-support-aa/1122420-candle-body-outline-wick-colors/page2[/URL]
          Hope it helps!

          Comment


            #6
            Hi s.kinra,
            I saw this script on the forum before.
            But, like the first script ("candleStick ++"), it changes the wick and body together.
            I want to change separately, ie colours for the bodies, colours for the borders and colours for the wicks.
            Do you know how to code this?

            Comment


              #7
              Hello rafaelcoisa,
              You can use candlestick++, if you have the logic how you would like to change the colors you can make a copy of it & make the changes. Candlestyle++ allows you to control body color - up / dn, body outline color- up / dn, doji color, if you need more add similarly. Yes, it currently uses outline color for wick, if you wish to make it seperate, you need to add 2 more brushes for wicks & modify high wick / low wick blocks for new brushes.
              Hope it helps!

              Comment


                #8
                Is there a reason for ninjatrader be like this because on all other platforms you have the possibility to separately change the body, the wick and the border colours.

                Comment


                  #9
                  They kept it simply vanilla and is open for any changes you like.

                  Comment


                    #10
                    Hello rafaelcoisa,

                    As this thread is not pertaining to NinjaScript development and c# programming, I have moved this thread to the NinjaScript File Sharing Discussion section of the forums.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hey guys,
                      I decided to try to understand the NinjaTrader_BrandonH strategy code and I figured out how to make the code work in a indicator.
                      But, I'm still unable to change the color of the wicks, they are really pegged to the border.
                      Isn't there a method to do this like "BarBrush" and "CandleOutlineBrush"?

                      Comment


                        #12
                        Hello rafaelocoisa,
                        There is no such method thru indicator to achieve this, you need your own candle style for this as I pointed you earlier. Hope it helps!

                        Comment


                          #13
                          i found the solution.

                          [CODE]
                          //
                          // Copyright (C) 2015, NinjaTrader LLC <www.ninjatrader.com>.
                          // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
                          //
                          #region Using declarations
                          using NinjaTrader.Data;
                          using NinjaTrader.Gui.Chart;
                          using SharpDX;
                          using SharpDX.Direct2D1;
                          using System;

                          //added
                          using System.ComponentModel;
                          using System.ComponentModel.DataAnnotations;
                          using System.Xml.Serialization;
                          using NinjaTrader.Gui;

                          #endregion

                          namespace NinjaTrader.NinjaScript.ChartStyles
                          {
                          /// <summary>
                          /// Sim22 for NT8b9 Mar 2016.
                          /// </summary>
                          public class bbb : ChartStyle
                          {
                          private object icon;

                          public override int GetBarPaintWidth(int barWidth)
                          {
                          return 1 + 2 * (barWidth - 1) + 2 * (int) WidthOutline;
                          }

                          public override object Icon
                          {
                          get
                          {
                          if (icon == null)
                          {
                          icon = NinjaTrader.Gui.Tools.Icons.ChartChartStyle;
                          }
                          return icon;
                          }
                          }

                          public override void OnRender(ChartControl chartControl, ChartScale chartScale, ChartBars chartBars)
                          {
                          Bars bars = chartBars.Bars;
                          float barWidth = GetBarPaintWidth(BarWidthUI);
                          Vector2 point0 = new Vector2();
                          Vector2 point1 = new Vector2();
                          RectangleF rect = new RectangleF();

                          SharpDX.Direct2D1.StrokeStyleProperties ssPropsWick = new SharpDX.Direct2D1.StrokeStyleProperties();
                          ssPropsWick.DashStyle = DashStyleWick;
                          SharpDX.Direct2D1.StrokeStyle styleWick = new SharpDX.Direct2D1.StrokeStyle(RenderTarget.Factory , ssPropsWick);
                          SharpDX.Direct2D1.AntialiasMode oldAntialiasMode = RenderTarget.AntialiasMode;
                          RenderTarget.AntialiasMode = SharpDX.Direct2D1.AntialiasMode.Aliased;

                          for (int idx = chartBars.FromIndex; idx <= chartBars.ToIndex; idx++)
                          {
                          Brush overriddenBarBrush = chartControl.GetBarOverrideBrush(chartBars, idx);
                          Brush overriddenOutlineBrush = chartControl.GetCandleOutlineOverrideBrush(chartBa rs, idx);
                          Brush upOutBrushDX = UpOutBrush.ToDxBrush(RenderTarget);
                          Brush dnOutBrushDX = DnOutBrush.ToDxBrush(RenderTarget);
                          Brush dojiBrushDX = DojiBrush.ToDxBrush(RenderTarget);
                          Brush upOutBrushWickDX = UpOutBrushWick.ToDxBrush(RenderTarget);
                          Brush dnOutBrushWickDX = DnOutBrushWick.ToDxBrush(RenderTarget);
                          Brush dojiBrushWickDX = DojiBrushWick.ToDxBrush(RenderTarget);

                          double closeValue = bars.GetClose(idx);
                          float closeY = chartScale.GetYByValue(closeValue);
                          float highY = chartScale.GetYByValue(bars.GetHigh(idx));
                          float lowY = chartScale.GetYByValue(bars.GetLow(idx));
                          double openValue = bars.GetOpen(idx);
                          float openY = chartScale.GetYByValue(openValue);
                          float x = chartControl.GetXByBarIndex(chartBars, idx);


                          if (Math.Abs(openY - closeY) < 0.0000001)
                          {
                          // Doji Line
                          point0.X = x - barWidth * 0.5f;
                          point0.Y = closeY;
                          point1.X = x + barWidth * 0.5f;
                          point1.Y = closeY;

                          TransformBrush(overriddenOutlineBrush ?? dojiBrushDX, new RectangleF(point0.X, point0.Y - WidthOutline, barWidth, WidthOutline));
                          RenderTarget.DrawLine(point0, point1, overriddenOutlineBrush ?? dojiBrushDX, WidthOutline);
                          }
                          else
                          {
                          // Candle
                          Brush brush = closeValue >= openValue ? UpBrushDX : DownBrushDX;
                          brush.Opacity = Opacity * 0.01f;
                          rect.X = x - barWidth * 0.5f + 0.5f;
                          rect.Y = Math.Min(closeY, openY);
                          rect.Width = barWidth - 1;
                          rect.Height = Math.Max(openY, closeY) - Math.Min(closeY, openY);
                          TransformBrush(overriddenBarBrush ?? brush, rect);
                          TransformBrush(overriddenOutlineBrush ?? (closeValue > openValue ? upOutBrushDX : dnOutBrushDX), rect);
                          RenderTarget.FillRectangle(rect, overriddenBarBrush ?? brush);
                          RenderTarget.DrawRectangle(rect, overriddenOutlineBrush ?? (closeValue > openValue ? upOutBrushDX : dnOutBrushDX), WidthOutline);

                          }

                          // High wick
                          if (highY < Math.Min(openY, closeY))
                          {
                          point0.X = x;
                          point0.Y = highY;
                          point1.X = x;
                          point1.Y = Math.Min(openY, closeY);
                          TransformBrush(overriddenOutlineBrush ?? (closeValue == openValue ? dojiBrushWickDX : closeValue > openValue ? upOutBrushWickDX : dnOutBrushWickDX), new RectangleF(point0.X - WidthWick, point0.Y, WidthWick, point1.Y - point0.Y));
                          RenderTarget.DrawLine(point0, point1, overriddenOutlineBrush ?? (closeValue == openValue ? dojiBrushWickDX : closeValue > openValue ? upOutBrushWickDX : dnOutBrushWickDX), WidthWick, styleWick);
                          }

                          // Low wick
                          if (lowY > Math.Max(openY, closeY))
                          {
                          point0.X = x;
                          point0.Y = lowY;
                          point1.X = x;
                          point1.Y = Math.Max(openY, closeY);
                          TransformBrush(overriddenOutlineBrush ?? (closeValue == openValue ? dojiBrushWickDX : closeValue > openValue ? upOutBrushWickDX : dnOutBrushWickDX), new RectangleF(point1.X - WidthWick, point1.Y, WidthWick, point0.Y - point1.Y));
                          RenderTarget.DrawLine(point0, point1, overriddenOutlineBrush ?? (closeValue == openValue ? dojiBrushWickDX : closeValue > openValue ? upOutBrushWickDX : dnOutBrushWickDX), WidthWick, styleWick);
                          }

                          upOutBrushDX.Dispose();
                          dnOutBrushDX.Dispose();
                          dojiBrushDX.Dispose();
                          upOutBrushWickDX.Dispose();
                          dnOutBrushWickDX.Dispose();
                          dojiBrushWickDX.Dispose();
                          }
                          styleWick.Dispose();
                          RenderTarget.AntialiasMode = oldAntialiasMode;

                          }

                          protected override void OnStateChange()
                          {
                          if (State == State.SetDefaults)
                          {
                          Name = @"bbb";
                          Description = "Plots customizable outline, wicks and bar opacity Candlesticks";
                          ChartStyleType = (ChartStyleType) 511;
                          this.UpBrush = System.Windows.Media.Brushes.Green;
                          this.DownBrush = System.Windows.Media.Brushes.DarkRed;
                          this.UpOutBrush = System.Windows.Media.Brushes.LimeGreen;
                          this.DnOutBrush = System.Windows.Media.Brushes.Red;
                          this.DojiBrush = System.Windows.Media.Brushes.Gray;
                          this.UpOutBrushWick = System.Windows.Media.Brushes.LimeGreen;
                          this.DnOutBrushWick = System.Windows.Media.Brushes.Red;
                          this.DojiBrushWick = System.Windows.Media.Brushes.Gray;
                          WidthOutline = 1f;
                          WidthWick = 1f;
                          Opacity = 85;
                          }
                          else if (State == State.Configure)
                          {
                          SetPropertyName("BarWidth", Custom.Resource.NinjaScriptChartStyleBarWidth);
                          SetPropertyName("DownBrush", "Colors - Down bar");
                          SetPropertyName("UpBrush", "Colors - Up bar");

                          Properties.Remove(Properties.Find("Stroke", true));
                          Properties.Remove(Properties.Find("Stroke2", true));

                          UpBrush.Freeze();
                          DownBrush.Freeze();
                          UpOutBrush.Freeze();
                          DnOutBrush.Freeze();
                          DojiBrush.Freeze();
                          UpOutBrushWick.Freeze();
                          DnOutBrushWick.Freeze();
                          DojiBrushWick.Freeze();
                          }
                          }
                          #region Properties

                          [XmlIgnore]
                          [Display(Name="Colors - Down bar outline", Description="Outline color of down bar", Order=1, GroupName="Chart Style")]
                          public System.Windows.Media.Brush DnOutBrush
                          { get; set; }

                          [Browsable(false)]
                          public string DnOutBrushSerializable
                          {
                          get { return Serialize.BrushToString(DnOutBrush); }
                          set { DnOutBrush = Serialize.StringToBrush(value); }
                          }

                          [XmlIgnore]
                          [Display(Name="Colors - Up bar outline", Description="Outline color of up bar", Order=2, GroupName="Chart Style")]
                          public System.Windows.Media.Brush UpOutBrush
                          { get; set; }

                          [Browsable(false)]
                          public string UpOutBrushSerializable
                          {
                          get { return Serialize.BrushToString(UpOutBrush); }
                          set { UpOutBrush = Serialize.StringToBrush(value); }
                          }

                          [XmlIgnore]
                          [Display(Name="Colors - Doji outline", Description="Color of doji bar", Order=3, GroupName="Chart Style")]
                          public System.Windows.Media.Brush DojiBrush
                          { get; set; }

                          [Browsable(false)]
                          public string DojiBrushSerializable
                          {
                          get { return Serialize.BrushToString(DojiBrush); }
                          set { DojiBrush = Serialize.StringToBrush(value); }
                          }

                          [XmlIgnore]
                          [Display(Name = "Colors - Down bar wick", Description = "Wick color of down bar", Order = 1, GroupName = "Chart Style")]
                          public System.Windows.Media.Brush DnOutBrushWick
                          { get; set; }

                          [Browsable(false)]
                          public string DnOutBrushWickSerializable
                          {
                          get { return Serialize.BrushToString(DnOutBrushWick); }
                          set { DnOutBrushWick = Serialize.StringToBrush(value); }
                          }

                          [XmlIgnore]
                          [Display(Name = "Colors - Up bar wick", Description = "Wick color of up bar", Order = 2, GroupName = "Chart Style")]
                          public System.Windows.Media.Brush UpOutBrushWick
                          { get; set; }

                          [Browsable(false)]
                          public string UpOutBrushWickSerializable
                          {
                          get { return Serialize.BrushToString(UpOutBrushWick); }
                          set { UpOutBrushWick = Serialize.StringToBrush(value); }
                          }

                          [XmlIgnore]
                          [Display(Name = "Colors - Doji wick", Description = "Wick color of doji bar", Order = 3, GroupName = "Chart Style")]
                          public System.Windows.Media.Brush DojiBrushWick
                          { get; set; }

                          [Browsable(false)]
                          public string DojiBrushWickSerializable
                          {
                          get { return Serialize.BrushToString(DojiBrushWick); }
                          set { DojiBrushWick = Serialize.StringToBrush(value); }
                          }

                          [Range(0, 100),NinjaScriptProperty]
                          [Display(Name="Opacity % (0-100)", Description="Opacity of bar.", Order=4, GroupName="Chart Style")]
                          public int Opacity
                          { get; set; }

                          [Range(1.0f, 20.0f),NinjaScriptProperty]
                          [Display(Name="Outline width", Description="Outline width.", Order=6, GroupName="Chart Style")]
                          public float WidthOutline
                          { get; set; }

                          [NinjaScriptProperty]
                          [Display(Name="Wick dashstyle", Description="Wick dashstyle.", Order=7, GroupName="Chart Style")]
                          public SharpDX.Direct2D1.DashStyle DashStyleWick
                          { get; set; }

                          [Range(1.0f, 20.0f),NinjaScriptProperty]
                          [Display(Name="Wick width", Description="Wick width.", Order=8, GroupName="Chart Style")]
                          public float WidthWick
                          { get; set; }

                          #endregion
                          }
                          }
                          [/CODE]

                          Comment


                            #14
                            [QUOTE=rafaelcoisa;n1172791]i found the solution.
                            [CODE]
                            //Your Script
                            [/CODE]
                            [/QUOTE]


                            Hi and thanks for sharing.
                            I'm getting compile errors while rebuilding the indicator in the Wizard.
                            Would you please share an exported zip file?
                            Here's an exporting tutorial
                            [URL="https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?export.htm"]https://ninjatrader.com/support/help...tml?export.htm[/URL]

                            Got it to work from this help from Jesse
                            [URL]https://ninjatrader.com/support/forum/forum/ninjatrader-8/add-on-development/1188230-wizard-for-importing-ninjascript-chartstyles-or-direct-cs-import?p=1188246#post1188246[/URL]
                            Attached Files
                            Last edited by PaulMohn; 02-03-2022, 03:25 PM.

                            Comment


                              #15
                              I've tested changing colors of the wicks independently than the bodies as this (lines 149 to 156 in script in previous post bbb.cs)
                              [CODE]
                              this.UpBrush = System.Windows.Media.Brushes.Green;
                              this.DownBrush = System.Windows.Media.Brushes.DarkRed;
                              [B]this.UpOutBrush = System.Windows.Media.Brushes.Pink;
                              this.DnOutBrush = System.Windows.Media.Brushes.Cyan;[/B]
                              this.DojiBrush = System.Windows.Media.Brushes.Gray;
                              [B]this.UpOutBrushWick = System.Windows.Media.Brushes.Pink;
                              this.DnOutBrushWick = System.Windows.Media.Brushes.Cyan;[/B]
                              this.DojiBrushWick = System.Windows.Media.Brushes.Gray;[/CODE]

                              but no different color in result.

                              How do you get the script to change the wicks color independently than the bodies? Thanks

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by habeebft, Today, 07:27 AM
                              1 response
                              13 views
                              0 likes
                              Last Post NinjaTrader_ChristopherS  
                              Started by AveryFlynn, Today, 04:57 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Max238, Today, 01:28 AM
                              4 responses
                              37 views
                              0 likes
                              Last Post Max238
                              by Max238
                               
                              Started by r68cervera, Today, 05:29 AM
                              1 response
                              10 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by geddyisodin, Today, 05:20 AM
                              1 response
                              14 views
                              0 likes
                              Last Post NinjaTrader_Gaby  
                              Working...
                              X