• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

help modding code

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

    help modding code

    hi

    With the following code there is some weird coloring.

    Can you help me mod the code so that the variables private int longcolour and private int shortcolour can be colors I choose? like red blue etc etc, ideally to choose from a colour picker..

    Thanks

    Code:
    #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>
        /// Trendathon
        /// </summary>
        [Description("Trendathon")]
        public class Trendathon : Indicator
        {
            #region Variables
            // Wizard generated variables
                private Color UpCol = Color.Blue; // Default setting for LongColour
                private Color DnCol = Color.Green; // Default setting for ShortColour
                private int barWidth = 1; // Default setting for BarWidth
            // User defined variables (add any user defined variables below)
    			private DataSeries		haClose;
    			private DataSeries		haOpen;
    			private DataSeries		icolor;
    		
            #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				= true;
    			haClose				= new DataSeries(this);
    			haOpen				= new DataSeries(this);
    			icolor				= new DataSeries(this);
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			double CompBars = 6 ;
    			Color UpCol = Color.FromArgb(15,90,180);
    			Color DnCol = Color.FromArgb(255,50,50);
    			//Color icolor = Color.FromArgb(255,50,50);
    			/*If LongColour = 0 then upcol = RGB(15,90,180)
    			Else UpCol = LongColour;
    
    			If ShortColour = 0 then dncol = RGB(255,50,50)
    			Else DnCol = ShortColour;*/
    
    			
    			if (CurrentBar == 1)
    			{
    				haOpen[0] = Open[0];
    				haClose[0] = (Open[0] + High[0] + Low[0] + Close[0])/4; 
    			}
    
    			if (CurrentBar > 1)
    			{
    				haClose[0] = (Open[0] + High[0] + Low[0] + Close[0])/4; 
    				haOpen[0] = (haOpen[1] + haClose[1])/2;
    
    				if (haClose[0] > haOpen[0])
    					icolor[0] = 1;
    				else icolor[0] = 2;
    				/////////////////////////////////////////
    				if (icolor[0] == 1)
    				{
    					BarColor = UpCol;
    				}
    				if (icolor[0] == 2)
    				{
    					BarColor = DnCol;
    				}
    				////////////////////////////////////////
    	
    				for (int x = 1; x <= CompBars; x++)
    				{
    					if  ((haOpen[0] <= Math.Max(haOpen[x],haClose[x])) &&
    					(haOpen[0] >= Math.Min(haOpen[x],haClose[x])) &&
    					(haClose[0] <= Math.Max(haOpen[x],haClose[x])) &&
    					(haClose[0] >= Math.Min(haOpen[x],haClose[x]))) 
    					icolor[0] = icolor[x];
    				}
    				if (icolor[0] == 1)
    				{
    					BarColor = UpCol;
    					CandleOutlineColor = UpCol;
    				}
    				if (icolor[0] == 2)
    				{
    					BarColor = DnCol;
    					CandleOutlineColor = DnCol;
    				}
    
    			}
    		}
    
            #region Properties
    
    		
    		[XmlIgnore()]
            [Description("Color for painted region")]
            [GridCategory("Parameters")]
            public Color Upcol
            {
                get { return Upcol; }
                set { Upcol = value; }
            }
    		
    		// Serialize our Color object
    		[Browsable(false)]
    		public string BorderColorSerialize
    		{
    			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(UpCol); }
    			set { UpCol = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    		}
    
    		[XmlIgnore()]
    		[Description("Color for painted region")]
            [GridCategory("Parameters")]
            public Color Dncol
            {
                get { return DnCol; }
                set { DnCol = value; }
            }
    		
    		[Browsable(false)]
    		public string FillColorSerialize
    		{
    			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(DnCol); }
    			set { DnCol = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
    		}
    		
    
            [Description("")]
            [GridCategory("Parameters")]
            public int BarWidth
            {
                get { return barWidth; }
                set { barWidth = Math.Max(1, value); }
            }
            #endregion
        }
    }
    Last edited by lucyjoy; 03-03-2014, 06:37 AM.

    #2
    Hello lucyjoy,

    Thank you for your post.

    I would recommend using the sample at the following link to create user defined colors: http://www.ninjatrader.com/support/f...ead.php?t=4977
    Patrick H.NinjaTrader Customer Service

    Comment


      #3
      Hi

      Thanks, I tried that!!!! Compiles fine..... Then when I add the indicator Ninjatrader Crashes and closes...

      Any Ideas?

      Code:
      #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>
          /// Trendathon
          /// </summary>
          [Description("Trendathon")]
          public class Trendathon : Indicator
          {
              #region Variables
              // Wizard generated variables
                  private Color UpCol = Color.Blue; // Default setting for LongColour
                  private Color DnCol = Color.Green; // Default setting for ShortColour
                  private int barWidth = 1; // Default setting for BarWidth
              // User defined variables (add any user defined variables below)
      			private DataSeries		haClose;
      			private DataSeries		haOpen;
      			private DataSeries		icolor;
      		
              #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				= true;
      			haClose				= new DataSeries(this);
      			haOpen				= new DataSeries(this);
      			icolor				= new DataSeries(this);
              }
      
              /// <summary>
              /// Called on each bar update event (incoming tick)
              /// </summary>
              protected override void OnBarUpdate()
              {
      			double CompBars = 6 ;
      			Color UpCol = Color.FromArgb(15,90,180);
      			Color DnCol = Color.FromArgb(255,50,50);
      			//Color icolor = Color.FromArgb(255,50,50);
      			/*If LongColour = 0 then upcol = RGB(15,90,180)
      			Else UpCol = LongColour;
      
      			If ShortColour = 0 then dncol = RGB(255,50,50)
      			Else DnCol = ShortColour;*/
      
      			
      			if (CurrentBar == 1)
      			{
      				haOpen[0] = Open[0];
      				haClose[0] = (Open[0] + High[0] + Low[0] + Close[0])/4; 
      			}
      
      			if (CurrentBar > 1)
      			{
      				haClose[0] = (Open[0] + High[0] + Low[0] + Close[0])/4; 
      				haOpen[0] = (haOpen[1] + haClose[1])/2;
      
      				if (haClose[0] > haOpen[0])
      					icolor[0] = 1;
      				else icolor[0] = 2;
      				/////////////////////////////////////////
      				if (icolor[0] == 1)
      				{
      					BarColor = UpCol;
      				}
      				if (icolor[0] == 2)
      				{
      					BarColor = DnCol;
      				}
      				////////////////////////////////////////
      	
      				for (int x = 1; x <= CompBars; x++)
      				{
      					if  ((haOpen[0] <= Math.Max(haOpen[x],haClose[x])) &&
      					(haOpen[0] >= Math.Min(haOpen[x],haClose[x])) &&
      					(haClose[0] <= Math.Max(haOpen[x],haClose[x])) &&
      					(haClose[0] >= Math.Min(haOpen[x],haClose[x]))) 
      					icolor[0] = icolor[x];
      				}
      				if (icolor[0] == 1)
      				{
      					BarColor = UpCol;
      					CandleOutlineColor = UpCol;
      				}
      				if (icolor[0] == 2)
      				{
      					BarColor = DnCol;
      					CandleOutlineColor = DnCol;
      				}
      
      			}
      		}
      
              #region Properties
      
      		
      		[XmlIgnore()]
              [Description("Color for painted region")]
              [GridCategory("Parameters")]
              public Color Upcol
              {
                  get { return Upcol; }
                  set { Upcol = value; }
              }
      		
      		// Serialize our Color object
      		[Browsable(false)]
      		public string BorderColorSerialize
      		{
      			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(UpCol); }
      			set { UpCol = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
      		}
      
      		[XmlIgnore()]
      		[Description("Color for painted region")]
              [GridCategory("Parameters")]
              public Color Dncol
              {
                  get { return DnCol; }
                  set { DnCol = value; }
              }
      		
      		[Browsable(false)]
      		public string FillColorSerialize
      		{
      			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(DnCol); }
      			set { DnCol = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
      		}
      		
      
              [Description("")]
              [GridCategory("Parameters")]
              public int BarWidth
              {
                  get { return barWidth; }
                  set { barWidth = Math.Max(1, value); }
              }
              #endregion
          }
      }

      Comment


        #4
        Please try with the lowercase color variables in your color serialization properties - i.e.

        get { return NinjaTrader.Gui.Design.SerializableColor.ToString( upCol); }
        set { upCol = NinjaTrader.Gui.Design.SerializableColor.FromStrin g(value); }

        Same for your dnCol one.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          [XmlIgnore()]
          [Description("Color for painted region")]
          [GridCategory("Parameters")]
          public Color Upcol
          {
          get { return Upcol; }
          set { Upcol = value; }
          }
          You have a circular reference here, marked by the red text.
          Last edited by koganam; 03-04-2014, 11:17 AM.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by connorgrant5, Today, 01:33 PM
          1 response
          12 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Started by Mykro, Today, 01:28 PM
          7 responses
          16 views
          0 likes
          Last Post Mykro
          by Mykro
           
          Started by dmking, Today, 01:57 PM
          1 response
          11 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by rwilliam, Today, 01:09 PM
          1 response
          24 views
          0 likes
          Last Post NinjaTrader_Melissa  
          Started by daqu40, Today, 01:08 PM
          2 responses
          10 views
          0 likes
          Last Post daqu40
          by daqu40
           
          Working...
          X