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

DashStyle error

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

    DashStyle error

    Hi,

    I am trying to set the line style to dash in this code and I keep getting the error "The name 'DashStyle' does not exist in the current context.

    I have tried to copy code from other posts exactly and no matter how I set the pen style I get this error.

    Code:
            protected override void Initialize()
            {
    			
    			Pen MyPen1 = new Pen(Color.Blue);
    			MyPen1.DashStyle = DashStyle.Dash;
    			
    			Add(new Plot(MyPen1, PlotStyle.Line,"Line"));
    			
                CalculateOnBarClose	= true;
                Overlay				= true;
                PriceTypeSupported	= true;
    			
    			MAHolder = new DataSeries(this);
    			
            }

    I am sure it something obvious, but I am missing it.
    Any help would be appreciated,

    Ryan

    #2
    Hello Ryan,

    Thank you for your post.

    Please try the following instead:
    Code:
    Plots[0].Pen.DashStyle = DashStyle.Dash;

    Comment


      #3
      Thanks Patrick,

      Unfortunately that was a version that I have already tried found in another post and get the same error.

      Ryan

      Comment


        #4
        Hello RyanR,

        That should not create an error. Please provide your full script for review.

        Comment


          #5
          Thanks Patrick,

          This was an existing set of code that would toggle a line on/off without reloading the indicator. I stripped out the logic for rising falling line color changes and want to add the ability to draw different line styles but simply changing the pen style does not seem to work. I am sure it something basic but can't seem to find it.

          Thanks,
          Ryan


          Code:
          #region Using declarations
          using NinjaTrader.Data;
          using NinjaTrader.Gui.Chart;
          using NinjaTrader.Gui.Design;
          using System.ComponentModel;
          using System.Drawing;
          using System;
          using System.Xml.Serialization;
          using System.Windows.Forms;
          #endregion
          
          // This namespace holds all indicators and is required. Do not change it.
          namespace NinjaTrader.Indicator
          {
              /// <summary>
              /// Enter the description of your new custom indicator here
              /// </summary>
              [Description("Enter the description of your new custom indicator here")]
              public class ToggleMA : Indicator
              {
                  #region Variables
          		
          		private MoveAvg	matype		= MoveAvg.EMA;
          		private int	period				= 150;
          		private int thickness			= 5;
          		private Color lineColor = Color.DarkBlue;
          		private ToolStrip strip 		= null;
          		private ToolStripButton button 	= null;
          		private  ToolStripSeparator myToolStripSeparator;
          		private bool show 				= true;
          
          		
          		private DataSeries MAHolder;
          		
          		#endregion
          		
          		
          		
                  protected override void Initialize()
                  {
          			
          			Pen MyPen1 = new Pen(Color.Blue);
          			Plots[0].Pen.DashStyle = DashStyle.Dash;
          			
          			Add(new Plot(MyPen1, PlotStyle.Line,"Line"));
          			
                      CalculateOnBarClose	= true;
                      Overlay				= true;
                      PriceTypeSupported	= true;
          			
          			MAHolder = new DataSeries(this);
          			
                  }
          		
          		public override string ToString()
          		{
          			return "";	
          		}
          		
          		protected override void OnStartUp()
          		{
          			string buttonText = "init";
          			
          			switch (matype)
          			{
          				case MoveAvg.EMA:
          				{
          					buttonText = "E "+Period.ToString();
          					break;
          				}
          				
          				case MoveAvg.HMA:
          				{
          					buttonText = "H "+Period.ToString();
          					break;
          				}
          				
          				case MoveAvg.SMA:
          				{
          					buttonText = "S "+Period.ToString();
          					break;
          				}
          				
          				case MoveAvg.WMA:
          				{
          					buttonText = "W "+Period.ToString();
          					break;
          				}
          			}
          			
          			Control[] tscontrol = ChartControl.Controls.Find("tsrTool",false);
          			
          			if(tscontrol.Length > 0)
          			{
          			  button = new ToolStripButton(buttonText);	
          			  button.Click += hideshow;
          			  myToolStripSeparator 	= new ToolStripSeparator ();
          			  strip = (ToolStrip) tscontrol[0];
          			  strip.Items.Add(myToolStripSeparator);
          			  strip.Items.Add(button);
          			  button.ForeColor = Color.Blue;
          			}
          			
          			Plots[0].Pen = new Pen(lineColor);
          			
          			base.OnStartUp();
          	
          		}
          		
          		
                  protected override void OnBarUpdate()
                  {
          		
          			if ( CurrentBar < period )
          				return;
          			
          			switch (matype)
          			{
          				case MoveAvg.EMA:
          				{
          					MAHolder.Set(EMA(Period)[0]);
          					break;
          				}
          				
          				case MoveAvg.HMA:
          				{
          					MAHolder.Set(HMA(Period)[0]);
          					break;
          				}
          				
          				case MoveAvg.SMA:
          				{
          					MAHolder.Set(SMA(Period)[0]);
          					break;
          				}
          				
          				case MoveAvg.WMA:
          				{
          					MAHolder.Set(WMA(Period)[0]);
          					break;
          				}
          			}
          			Line.Set(MAHolder[0]);
          		
                  }
          		
          
          		private void hideshow(object s, EventArgs e)
          		{
          			if ( show == false ) 
          			{
          				Plots[0].Pen = new Pen(Color.Transparent);
          				show = true;
          				button.ForeColor = Color.Silver;
          			}
          			else
          			{
          				Plots[0].Pen = new Pen (LineColor,Thickness);
          				show = false;
          				button.ForeColor = Color.Blue;
          			}
          			
          			ChartControl.ChartPanel.Refresh();
          		}
          
          		
          
          
          		protected override void OnTermination()
          		{
          		   	if((strip != null) && (button != null))
          			{
          		        strip.Items.Remove(button);
          				strip.Items.Remove(myToolStripSeparator);
          			}
          			
          			strip = null;
          			button = null;
          			myToolStripSeparator = null;
          			base.Dispose();
          			
          		}		
          
                  #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
                  public DataSeries Line
                  {
                      get { return Values[0]; }
                  }
          
          		
          		[Description("Choose a Moving Average type.")]
                  [GridCategory("Settings")]
          		[Gui.Design.DisplayName("1. Choose MA Type")]
          		public MoveAvg MAType
          		{
          			get { return matype; }
          			set { matype = value; }
          		}
          		
          		[Description("Numbers of bars used for calculations")]		
                  [GridCategory("Settings")]
          		[Gui.Design.DisplayName("2. MA Lookback Period")]
          		public int Period
          		{
          			get { return period; }
          			set { period = Math.Max(1, value); }
          		}
          		
          		[Description("Lines Thickness")]
                  [GridCategory("Settings")]
          		[Gui.Design.DisplayName("3. MA Line Thinkness")]
          		public int Thickness
          		{
          			get { return thickness; }
          			set { thickness = Math.Max(1, value); }
          		}
          		
          		[Description("Bar Color Up - override")]
                  [GridCategory("Settings")]
          		[Gui.Design.DisplayName("4. Line Color")]
                  public Color LineColor
                  {
                      get { return lineColor; }
                      set { lineColor = value; }
                  }
          		
          		[Description("Bar Color Up - override")]
                  [GridCategory("Settings")]
          		[Gui.Design.DisplayName("5. Neutral Color")]
          		[Browsable(false)]
          		public string lineColorSerialize
          		{
          			get { return NinjaTrader.Gui.Design.SerializableColor.ToString(lineColor); }
          			set { lineColor = NinjaTrader.Gui.Design.SerializableColor.FromString(value); }
          		}
          		
          				
          		#endregion
              }
          }
          
          
           public enum MoveAvg
          {
          	EMA,
          	HMA,
          	SMA,
          	WMA,
          }

          Comment


            #6
            Hello RyanR,

            I am not receiving any errors with your code. Please provide a screenshot of the error with the message clearly visible.

            Comment


              #7
              Screen Shot

              Here it is Patrick
              Attached Files

              Comment


                #8
                Patrick,

                I have also taken the code I sent you and created a new indicator (deleted the old one), recompiled and same context error.

                Ryan

                Comment


                  #9
                  Hello RyanR,

                  Thank you for your patience.

                  Please attach the .cs file for the indicator to your response. You will find the .cs file under (My) Documents\NinjaTrader 7\bin\Custom\Indicator.

                  Comment


                    #10
                    Patrick,

                    The attached is the code it was renamed when I deleted the old version.

                    Thanks,

                    Ryan
                    Attached Files

                    Comment


                      #11
                      Hello RyanR,

                      Thank you for your response.

                      Your using declarations section of the code needs to reflect the following below:
                      Code:
                      #region Using declarations
                      using System;
                      using System.ComponentModel;
                      using System.Diagnostics;
                      using System.Drawing;
                      using System.Drawing.Drawing2D;
                      using System.Xml.Serialization;
                      using System.Collections;
                      using NinjaTrader.Cbi;
                      using NinjaTrader.Data;
                      using NinjaTrader.Gui.Chart;
                      using System.Windows.Forms;
                      #endregion

                      Comment


                        #12
                        Thanks Patrick!

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by alifarahani, Today, 09:40 AM
                        6 responses
                        38 views
                        0 likes
                        Last Post alifarahani  
                        Started by Waxavi, Today, 02:10 AM
                        1 response
                        17 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by Kaledus, Today, 01:29 PM
                        5 responses
                        14 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Started by Waxavi, Today, 02:00 AM
                        1 response
                        12 views
                        0 likes
                        Last Post NinjaTrader_LuisH  
                        Started by gentlebenthebear, Today, 01:30 AM
                        3 responses
                        17 views
                        0 likes
                        Last Post NinjaTrader_Jesse  
                        Working...
                        X