Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.



    Let me know if I can be of further assistance.

    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.

        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); }
            }

            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.

                  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 aa731, Today, 02:54 AM
                    0 responses
                    4 views
                    0 likes
                    Last Post aa731
                    by aa731
                     
                    Started by thanajo, 05-04-2021, 02:11 AM
                    3 responses
                    470 views
                    0 likes
                    Last Post tradingnasdaqprueba  
                    Started by Christopher_R, Today, 12:29 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post Christopher_R  
                    Started by sidlercom80, 10-28-2023, 08:49 AM
                    166 responses
                    2,237 views
                    0 likes
                    Last Post sidlercom80  
                    Started by thread, Yesterday, 11:58 PM
                    0 responses
                    4 views
                    0 likes
                    Last Post thread
                    by thread
                     
                    Working...
                    X