Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Color of Bar not changable

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

    Color of Bar not changable

    hi mates

    i programm a indicator where i want to set the color for it in the indicator propertys window. I can see the two color fields (propertys), but when i change the color, it does not take effect on the chart, even i reload the chart or remove and apply the indicator again.

    Here's what i have:

    Code of the region Variables:

    #region Variables
    // Wizard generated variables
    // User defined variables (add any user defined variables below)

    public Color pinbarUpColor = Color.Magenta;

    #endregion


    Code on Bar update:

    if(Open[0] > (LastLow+(BarRange*LongOpen))
    && Close[0] > (LastLow+(BarRange*LongClose))

    {
    //Change the Bar color
    BarColor = pinbarUpColor;

    // Paints a up arrow on the current bar 1 tick below the low
    DrawArrowUp("PinUp"+High[0], true, 0, Low[0] - TickSize, pinbarUpColor);

    //Throw Alarm
    Alert("LONG-PinBarAlert", NinjaTrader.Cbi.Priority.High, "New LONG Pinbar", "Alert1.wav", 10, Color.Black, pinbarUpColor);

    }

    Code for #region Properties:
    [Description("Color for the Up PinBar")]
    public Color PinbarUpColor
    {
    get { return pinbarUpColor; }
    set { pinbarUpColor = value; }
    }


    I'm not a professional but i dont understand, why i can see the colors and even change them, but no effect on the chart happens.

    thank you for helping me
    esatino

    #2
    Hello,

    Thanks for your forum post.

    When I run this line here on my side:

    BarColor = pinbarUpColor;


    It changes the color of my bars. This would lead me to believe that this line is not be executed.

    Unless your taking about changing the colors via a property. In this case this is not working since your not serializing it correctly. You would need to follow this sample for user definable color parameters.

    http://www.ninjatrader.com/support/f...ead.php?t=4977

    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Hi Brett

      TNX for the quick feedback.
      I changed it accordingly.

      Now, i can change the color in the Indi. propertys and the bar is painted in the color i choose.

      But now i have the following problem:
      a) i pull up a new chart
      b) i add the indicator
      c) choose the color i want and apply- and OK' it. (...bar is in the selected color, fine)
      d) i save the chart as a template
      e) i open e fresh new chart and apply the template to it, which has the Indicator included.

      Problem:
      I have to re set the colors in the indicator again.
      ...and further more, when i close NJT and reopen it, i again have to change the color in the
      indicator §8-)

      So, probably just a tiny thing i have to add/change?

      Happy coding
      esatino

      Comment


        #4
        Hello,

        Please recheck you closely, being sure to pay attention to the capital letter in the front of the variable names for example.

        Then you have correctly followed the color sample. If it is folowed the color will serialize and be able to keep saved to workspace and transfer via the template feature.

        This requires the second serizing parameter mentioned in the same to achieve this.

        [Browsable(false)]
        public string PaintColorSerialize
        {
        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( paintColor); }
        set { paintColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
        }

        If still having issues please post your code and I can give it a quick look for whats missing.

        I look forward to assisting you further.
        BrettNinjaTrader Product Management

        Comment


          #5
          In my opinion its ok
          __________________________
          #region Using declarations
          using System;
          using System.ComponentModel;
          using System.Diagnostics;
          using System.Drawing;
          using System.Drawing.Drawing2D;
          using System.Xml.Serialization;
          using NinjaTrader.Cbi;
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          #endregion

          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
          /// <summary>
          /// PinBar Indicator by Emilio Sabatino, www.oscom.ch, www.tradingcoach.ch
          /// Version 2.1 RC, added: Color Porpertys,Arrows, Color Alerts
          /// </summary>
          [Description("Enter the description of your new custom indicator here")]
          public class PinBar : Indicator
          {
          #region Variables
          // Wizard generated variables
          // User defined variables (add any user defined variables below)

          double ShortOpen = 0.65;
          double ShortClose = 0.65;

          double LongOpen = 0.65;
          double LongClose = 0.65;

          double pinFactor = 2.5;


          public Color pinBarDownColor = Color.Red;
          public Color pinBarUpColor = Color.White;

          #endregion

          /// <summary>
          /// This method is used to configure the indicator and is called once before any bar data is loaded.
          /// </summary>
          protected override void Initialize()
          {
          Overlay = false;

          // Calculate on the close of each bar
          CalculateOnBarClose = true;

          }

          /// <summary>
          /// Called on each bar update event (incoming tick)
          /// </summary>
          protected override void OnBarUpdate()
          {

          double LastLow = Low[0];
          double LastHigh = High[0];
          double BarRange = Range()[0];

          //Check for LONG PinBars
          if(Open[0] > (LastLow+(BarRange*LongOpen))
          && Close[0] > (LastLow+(BarRange*LongClose))
          && Open[0] > Low[1]
          && Close[0] > Low[1]
          //Additionaly check for Long PinBars
          && ((High[0]-Open[0])*pinFactor) < Open[0]-Low[0]
          && ((High[0]-Close[0])*pinFactor) < Close[0]-Low[0])

          {
          BarColor = pinBarUpColor;

          // Paints a up arrow on the current bar 1 tick below the low
          DrawArrowUp("PinUp"+High[0], true, 0, Low[0] - TickSize, pinBarUpColor);

          //Throw Alarm
          Alert("LONG-PinBarAlert", NinjaTrader.Cbi.Priority.High, "New LONG Pinbar", "Alert1.wav", 10, Color.Black, pinBarUpColor);

          }

          //Check for Short PinBars
          if(Open[0] < (LastHigh -(BarRange*ShortOpen))
          && Close[0] < (LastHigh -(BarRange*ShortClose))
          && Open[0] < High[1]
          && Close[0] < High[1]
          //Additionaly check for Long PinBars
          && ((Open[0]-Low[0])*pinFactor) < High[0]-Open[0]
          && ((Close[0]-Low[0])*pinFactor) < High[0]-Close[0])


          {
          BarColor = pinBarDownColor;

          // Paints a Down arrow on the current bar 1 tick above the high
          DrawArrowDown("PinDown"+Low[0], true, 0, High[0] + TickSize, pinBarDownColor);

          //Throw Alarm
          Alert("SHORT-PinBarAlert", NinjaTrader.Cbi.Priority.High, "New SHORT Pinbar", "Alert1.wav", 10, Color.Black, pinBarDownColor);
          }
          }

          #region Properties
          //[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
          [XmlIgnore()] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
          [Description("Color for the Down PinBar")]
          [GridCategory("Parameters")]

          //PinBarDownColor
          public Color PinBarDownColor
          {
          get { return pinBarDownColor; }
          set { pinBarDownColor = value; }
          }

          // Serialize PinBarDownColor
          [Browsable(false)]
          public string PinBarDownColorSerialize
          {
          get { return NinjaTrader.Gui.Design.SerializableColor.ToString( pinBarDownColor); }
          set { pinBarDownColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
          }

          [Description("Color for the Up PinBar")]
          [GridCategory("Parameters")]
          public Color PinBarUpColor
          {
          get { return pinBarUpColor; }
          set { pinBarUpColor = value; }
          }

          // Serialize PinBarUpColor
          [Browsable(false)]
          public string PinBarUpColorSerialize
          {
          get { return NinjaTrader.Gui.Design.SerializableColor.ToString( pinBarUpColor); }
          set { pinBarDownColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
          }

          public double PinFactor
          {
          get { return pinFactor; }
          set { pinFactor = Math.Min(10, value); }
          }

          #endregion
          }
          }

          Comment


            #6
            Hello,

            You had the following error you forgot to change it do down: See how your trying to seriealize the PinBarUpColor yet your setting pinBarDownColor.

            Change the set to UpColor then you should be good to go. I tested it on my side.

            // Serialize PinBarUpColor
            [Browsable(false)]
            public string PinBarUpColorSerialize
            {
            get { return NinjaTrader.Gui.Design.SerializableColor.ToString( pinBarUpColor); }
            set { pinBarDownColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
            }
            BrettNinjaTrader Product Management

            Comment


              #7
              from trees and forests §8-)

              holy cow !!!

              ...sometimes when diging in the code, i see so many trees that i can not see the forest anymore §8-)

              thank you very much!
              that thing was driving me crazy ;-)

              you guys are so great...i really know why i use your software!

              thanks again & happy coding
              emilio

              Comment


                #8
                Originally posted by NinjaTrader_Brett View Post
                Hello,

                You had the following error you forgot to change it do down: See how your trying to seriealize the PinBarUpColor yet your setting pinBarDownColor.

                Change the set to UpColor then you should be good to go. I tested it on my side.

                // Serialize PinBarUpColor
                [Browsable(false)]
                public string PinBarUpColorSerialize
                {
                get { return NinjaTrader.Gui.Design.SerializableColor.ToString( pinBarUpColor); }
                set { pinBarDownColor = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }
                }

                Can you please repost the full and corrected code?

                Comment


                  #9
                  This post was from 2011. Likely you will not be able to get original poster or my self to post full code since I just do not have the file anymore.
                  BrettNinjaTrader Product Management

                  Comment


                    #10
                    Originally posted by NinjaTrader_Brett View Post
                    This post was from 2011. Likely you will not be able to get original poster or my self to post full code since I just do not have the file anymore.
                    but the code is already posted "scroll above" or look here http://ninjatrader.com/support/forum...31&postcount=5

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by MidenThur, Today, 12:52 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post MidenThur  
                    Started by seseoraf, Today, 12:51 AM
                    1 response
                    5 views
                    0 likes
                    Last Post charmingishagarg  
                    Started by Rosario, Today, 12:50 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Rosario
                    by Rosario
                     
                    Started by kemoyums, Today, 12:38 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post kemoyums  
                    Started by MartynBashi, Yesterday, 11:01 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post MartynBashi  
                    Working...
                    X