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!
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
NinjaTrader
global namespace error already contains defination
Collapse
X
-
Been there, done that. The problem is the enum. This is the global namespace pollution issue -- best answer is "Don't Do That!" You have no business putting names in the global namespace. It is wrong.
Solution: wrap the enum in a unique namespace, perhaps the same name as the indicator. Add a "using" line for the new namespace, so that the Magic Code at the end will be able to find the enum.
That should take care of you.
--EV
-
Thanks for helping out here, EV. Yes, issue is likely with the scope of your enum.
You only need enums declared once per namespace and it will still be available from the copied, new indicator. You should be able to delete the enum declaration completely and it will compile.Ryan M.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_RyanM View PostThanks for helping out here, EV. Yes, issue is likely with the scope of your enum.
You only need enums declared once per namespace and it will still be available from the copied, new indicator. You should be able to delete the enum declaration completely and it will compile.
- It is bad practice to put names in the global namespace to begin with. Just quit doing that! Wrap them in a namespace. That's what namespaces are for.
- Since they are in separate indicators, he will be up the proverbial creek if someone wants his indicator that fails to have the definition, but does not want the one that keeps the definition.
- Keeping just one of them establishes a strong linkage between the two indicators -- which is a Bad Idea. What happens if one of the indicators later finds a need to change the enum?
Please, folks ... V7 forces enums for parameters up to a high level. Please wrap them in a namespace, rather than letting them pollute the global namespace. That pollution is just plain bad software engineering.
Example: his first enum is MovingAverageType -- hardly a unique name. What happens if I make one of the same -- it will build fine for me, since I do not have his indicator installed. A problem for anyone who wants to install both of our indicators, however. Please, just use namespaces and put nothing in the global namespace.
--EVLast edited by ETFVoyageur; 01-17-2011, 02:18 PM.
Comment
-
I didn't create the original indicators I using and modifying.. Can u give me a quick example as to how to wrap them,, maybe a sample code like the ones ninja has to demonstrate various things.. I am interested in exporting my code to some buddies, and seems like this is an issue if we all go to the same code thats available in the public domain
Comment
-
Originally posted by gg80108 View PostI didn't create the original indicators I using and modifying.. Can u give me a quick example as to how to wrap them,, maybe a sample code like the ones ninja has to demonstrate various things.. I am interested in exporting my code to some buddies, and seems like this is an issue if we all go to the same code thats available in the public domain
--EV
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; using RwbDemoModel; #endregion namespace RwbDemoModel { // This namespace is to prevent polluting the global namespace public enum DemoEnum {value1, value2} }
- Likes 1
Comment
-
Originally posted by gg80108 View PostI used the "save as" and copied and indicator.. The copy wont compile,, I attached the error and the part the code that is probable causing the error.. How do I fix this?
Example:
Code:// NT standard "Using Declarations section is here using _nsDataBoxTest; namespace _nsDataBoxTest { public enum MovAvgType { EMA, SMA, HMA, None } } // This namespace holds all indicators and is required. Do not change it. namespace NinjaTrader.Indicator // rest of the code goes here
Comment
-
Originally posted by gg80108 View PostIf this is in the indicator,, if I want to call this indicator in a strategy,, I have to add
using _nsDataBoxTest;
to the
Using Declarations section in my strategy also?
Comment
-
Enum vs Namespace
So if I understand correctly, if I place my Enums in a namespace they will only work in that indicator and not others that use the same enum? ie they are not global?
So the MAType example would only be available to that script and not others?
Comment
-
I found that these issues show up if u do the "save as" on an indicator with enums/namespace and then try to compile.. For us non geeks not sure why NT doesn't take care of this when it allows u to " save as", guess NT thought that just changing the strategy name would be good enough?
I did find that if I do a "save as" that has some enums wrapped in a namespace,, that I have to change the namespace name in the copy,, which is better then having to alter all the enum names if there are several enums..
Also found that I have to add the namespace in the declaration using of a strategy if I want to use the indicator in a strategy
Comment
-
As to the saving -- it actually works quite well
There are two cases -- either (a) you do not want the namespace changed when you do Save As ... , such as when you want to use the enum across several of your own indicators or (b) you do want the namespace changed, such as when you want the enum unique to that indicator.
In the case of (b) which is what you seemed to want -- just follow my convention. I name the namespace the same as my indicator. Then when Save As ... does its text substitution it updates the namespace name as well. This convention is pretty well guaranteed to not collide, since you cannot have two indicators of the same name anyway.
In the case of (a) pick any namespace name you like that is unlikely to get picked by someone else, and not the same as your indicator name. Then Save As ... will not touch it.
Put another way, here is my suggestion:
- If you have things to share between scripts of yours, (enums, classes, struct definitions, static library functions, etc) put them in a namespace that is unique to you, but does not match any script name. Save As... will not bother this namespace name.
- If you have things that are unique to a single script (e.g. enum properties) , put them in a namespace whose name matches the script name. That is pretty well guaranteed to not collide with anything else, including your own other scripts, because the script itself must be a unique name. By making the namespace name and the script name match, Save As... will update both.
--EVLast edited by ETFVoyageur; 01-26-2011, 10:40 AM.
Comment
-
-
See my previous posting.
In your case you have two indicators with the same namespace declaring the same enums. You can only declare the same enum once per namespace.
By the way, please try to pick a namespace name that is likely to be unique to you. Something like "Avgtype" is too likely to collide with one in use by some other indicator that a user may have also installed.
As I suggested in my last post, I suggest using the indicator name as the namespace name too.
--EV
Comment
-
Updating this thread here as we have lately seen issues following this approach. If you export as an assembly, your enums declared in their own namespace may not import correctly on another machine. Official recommendation on enum placement is shown in this sample:
Ryan M.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Padan, Today, 02:02 AM
|
9 responses
21 views
0 likes
|
Last Post Today, 03:27 PM | ||
Started by spottysallrite, Today, 11:31 AM
|
7 responses
21 views
0 likes
|
Last Post Today, 03:26 PM | ||
Started by nandhumca, Today, 03:15 PM
|
1 response
2 views
0 likes
|
Last Post Today, 03:23 PM | ||
Started by PopovDS, 03-11-2024, 12:49 PM
|
3 responses
17 views
0 likes
|
Last Post
by PopovDS
Today, 03:16 PM
|
||
Started by Lele2k24, Yesterday, 11:24 AM
|
12 responses
37 views
0 likes
|
Last Post Today, 03:07 PM |
Comment