• 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

CS0118 error Indicator is a type but it is used as a variable

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

    CS0118 error Indicator is a type but it is used as a variable

    This thread is mainly to inform people of how I resolved the error code CS0118 as I couldn't find the solution anywhere. Yet I still have questions on why do I need the line
    PriceTypeSupported = true;
    to resolve the error.
    G.
    -------------------------------------------------------------------------------------
    The offending line is in the indicator that includes MyIndicator:
    MyIndicator manyEma = MyIndicator();

    and in MyIndcator I basically have:
    protected override void Initialize() {
    Add(new Plot(Color.Green, "EMA"));
    Plots[0].Pen.Width = 2;
    Plots[0].Pen.DashStyle = DashStyle.Dash;
    PriceTypeSupported = true;
    }
    [Browsable(false)]
    [XmlIgnore()]
    public DataSeries EMAflat { get { return Values[0]; }

    Obviously the NinjaTrader generated code for the cache needs to be re-generate for the error to disappear.

    #2
    Hello giogio1,

    Thanks for your post.

    In the code you have provided, I do not see the context where you have hit a CS0118 compiler error. Setting PriceTypeSupported should not effect this error.

    In your code I see that you are instantiating your added indicator outside of any method in the Indicator class which would throw a CS0120 compiler error. If you test the code below, you should not receive an error.

    Code:
    public class MyHostingIndicator : Indicator
    {		
    	private EMA myEMA;
    
            /// <summary>
            /// This method is used to configure the indicator and is called once before any bar data is loaded.
            /// </summary>
            protected override void Initialize()
            {
                    Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "EMAPlot"));
    		Plots[0].Pen.Width = 2;
    		Plots[0].Pen.DashStyle = DashStyle.Dash;
                    Overlay				= true;
            }
    
    	protected override void OnStartUp()
    	{
    		myEMA = EMA(14);
    	}
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                    EMAPlot.Set(myEMA[0]);
            }
    
            #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 EMAPlot
            {
                    get { return Values[0]; }
            }
    
            #endregion
    }
    Some light information on C# compiler errors are noted in our NT7 help guide. I'll provide a link below. For more in depth information on C# compiler errors, I recommend checking external resources.

    Compiler Errors - https://ninjatrader.com/support/help...rror_codes.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NinjaCustomer, Today, 12:57 AM
    1 response
    3 views
    0 likes
    Last Post NinjaCustomer  
    Started by lancasterstephen, Today, 12:09 AM
    1 response
    3 views
    0 likes
    Last Post lancasterstephen  
    Started by liltr3d, Yesterday, 10:52 PM
    0 responses
    3 views
    0 likes
    Last Post liltr3d
    by liltr3d
     
    Started by Longhornmark, Yesterday, 08:25 AM
    3 responses
    13 views
    0 likes
    Last Post bltdavid  
    Started by mohdhm, Yesterday, 04:09 PM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ShawnB  
    Working...
    X