![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Indicator Development Support for the development of custom indicators using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
|
I 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?
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Dec 2010
Posts: 470
Thanks: 0
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#3 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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 |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Dec 2010
Posts: 470
Thanks: 0
Thanked 4 times in 4 posts
|
Quote:
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. --EV
Last edited by ETFVoyageur; 01-17-2011 at 01:18 PM.
|
|
|
|
|
|
|
#5 |
|
Senior Member
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
|
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
|
|
|
|
|
|
#6 | |
|
Senior Member
Join Date: Dec 2010
Posts: 470
Thanks: 0
Thanked 4 times in 4 posts
|
Quote:
--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}
}
|
|
|
|
|
|
|
#7 | |
|
Senior Member
|
Quote:
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
|
|
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
|
If 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? |
|
|
|
|
|
#9 |
|
Senior Member
|
Technically, if the Strategy is calling the indicator, then the indicator knows its NameSpace requirements, and should just use them. However, I do not remember testing this directly, so you may just have to try it and see. I am pretty sure I have done it in a Strategy test; I just cannot remember, as my trading methods are now pretty set, and will not change until they stop working.
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Mar 2008
Location: UK West Sussex
Posts: 665
Thanks: 9
Thanked 9 times in 7 posts
|
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? |
|
|
|
|
|
#11 |
|
Senior Member
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
|
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 |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Dec 2010
Posts: 470
Thanks: 0
Thanked 4 times in 4 posts
|
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:
--EV
Last edited by ETFVoyageur; 01-26-2011 at 09:40 AM.
|
|
|
|
|
|
#13 |
|
Senior Member
Join Date: Dec 2008
Location: Castle Pines, Co
Posts: 621
Thanks: 1
Thanked 2 times in 2 posts
|
Enclosed is my save as results,, less then trouble free.. Am I doing something wrong setting this up?
Think ur wisdom just dawned on me "I name the namespace the same as my indicator. Then when Save As ... does its text substitution it updates the namespace name as well."
Last edited by gg80108; 01-26-2011 at 09:50 AM.
|
|
|
|
|
|
#14 |
|
Senior Member
Join Date: Dec 2010
Posts: 470
Thanks: 0
Thanked 4 times in 4 posts
|
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 |
|
|
|
|
|
#15 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
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:
http://www.ninjatrader.com/support/f...ead.php?t=3420
Ryan M
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compile error message with namespace | tradervick | Strategy Development | 6 | 01-12-2011 03:00 PM |
| Polluting the global namespace | ETFVoyageur | Indicator Development | 4 | 01-06-2011 04:27 AM |
| namespace | trend | Version 7 Beta General Questions & Bug Reports | 1 | 10-21-2010 08:48 AM |
| Global Namespace Error when saving | ThatManFromTexas | Indicator Development | 6 | 05-07-2010 07:45 AM |
| Z-ordering of global drawing tools error | rtrader | Version 7 Beta General Questions & Bug Reports | 10 | 05-03-2010 02:51 PM |