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

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 jclose, Today, 09:37 PM
    0 responses
    3 views
    0 likes
    Last Post jclose
    by jclose
     
    Started by WeyldFalcon, 08-07-2020, 06:13 AM
    10 responses
    1,413 views
    0 likes
    Last Post Traderontheroad  
    Started by firefoxforum12, Today, 08:53 PM
    0 responses
    9 views
    0 likes
    Last Post firefoxforum12  
    Started by stafe, Today, 08:34 PM
    0 responses
    10 views
    0 likes
    Last Post stafe
    by stafe
     
    Started by sastrades, 01-31-2024, 10:19 PM
    11 responses
    169 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Working...
    X