Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Indicator Development

Indicator Development Support for the development of custom indicators using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 09-18-2017, 12:13 PM   #1
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default enumeration in multiple indicators

I created an indicator with enumeration values.

I then created another indicator with the same indicator values and NT states it already exists.

Is there a way to encapsulate the enumeration so it will ONLY stay within its own indicator
ballboy11 is offline  
Reply With Quote
Old 09-18-2017, 12:31 PM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,068
Thanks: 28
Thanked 1,053 times in 985 posts
Default

Hello,

Thank you for the post.

Generally speaking, if two separate indicators have two separate enums they should be defined as separate names in case you are defining them outside of the indicators class. If you are defining them inside the class, it should not have problems seeing them in the same scope:

Code:
public class Test1 : Indicator
{
	public enum MyCustomEnum{
	     one,two,three
	}
}
In the case you are making two indicators that use the same enum, that enum should instead be defined in a separate file that is not an Indicator specifically. In this case, you could generate a new indicator and delete all the default code and replace it with the following to define your shared enum:

MyEnum.cs inside of the Indicators folder.
Code:
namespace NinjaTrader.Indicator.MyEnumNamespace
{
   public enum MyCustomEnum{
	one,two,three
	}
}

After doing this, both indicators can then use the enum while using the fully qualified name:


Code:
private NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum myEnumVariable;


protected override Intialize()
{
 myEnumVariable= NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum.one;
}
This would require that you select the file with the Enum defined in addition to your indicator when exporting, meaning you would export the indicator Test1 and the file containing the enum definition MyEnum.cs per the example.



I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 09-18-2017, 12:56 PM   #3
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default

you can not initialize them in a class because nt can not find them
ballboy11 is offline  
Reply With Quote
Old 09-18-2017, 12:57 PM   #4
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default

i tried to create an enum inside a class and it gives errors

this is what i would have


public class myPanel : Indicator
{

public enum eZigZagDeviation
{
POINTS,
PERCENT
}



public eZigZagDeviation eZigZagType = eZigZagDeviation.POINTS;
[Description("Pivot Type (Swing/ZigZag)")]
[GridCategory("Pivot Type")]
[Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
public eZigZagDeviation ZigZagType
{
get { return eZigZagType; }
set { eZigZagType = value; }
}


if it is outside the indicator class it works
Attached Images
File Type: jpg nodraw.JPG (63.5 KB, 2 views)
Last edited by ballboy11; 09-18-2017 at 01:04 PM.
ballboy11 is offline  
Reply With Quote
Old 09-18-2017, 01:27 PM   #5
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default

now I have a crazy issue this is what I have


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 System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace NinjaTrader.Indicator
{
//

public enum ePanelForZigZag
{
POINTS,
PERCENT
}



//stufff


#region Properties


private ePanelForZigZag ePanelZigZagType = ePanelForZigZag.POINTS;
[Description("Pivot Type (Swing/ZigZag)")]
[GridCategory("Pivot Type")]
[Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
public ePanelForZigZag PanelZigZagType
{
get { return ePanelZigZagType; }
set { ePanelZigZagType = value; }

}


i add the enum no problem then i add the parameter i get an error
Attached Images
File Type: jpg nodraw.JPG (64.1 KB, 1 views)
ballboy11 is offline  
Reply With Quote
Old 09-18-2017, 02:12 PM   #6
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 4,068
Thanks: 28
Thanked 1,053 times in 985 posts
Default

Hello,

Thank you for the reply.

In this case, it looks like you have not copied the example I had provided exactly, you are not using the full namespace name when trying to access your enum.

Because this is inside of the class, and NinjaTrader works differently than a standard C# application you would need to explicitly point to the enum everywhere you have used it. This is also the case when exporting scripts that use enums, the full name should always be used and using statements should be avoided.

For your public property, it would look like the following:

Code:
private NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum myEnumVariable = NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum.one;
       
		
[Description("Pivot Type (Swing/ZigZag)")]
[GridCategory("Pivot Type")]
[Gui.Design.DisplayName("Pivot Type (Points/Percent)")]
public NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum MyEnumProperty
{
	get { return myEnumVariable; }
	set { myEnumVariable = value; }
}
I would suggest reverting to a state where you can compile once again, and then retry using the previous example ensuring to use the full namespace name everywhere you use the enum: NinjaTrader.Indicator.MyEnumNamespace.MyCustomEnum

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 09-20-2017, 06:09 AM   #7
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default creating enum in a seperate file

I am having too many issues with my enum and I wil just place it in a seperate file now does nt7 and nt8 have differerent methods of creating a a seperate enum?

Secondly how do I create an enum as a second file and acces this enum?

I thought I had it working. It works in open source, it compiles as a dll but installation gives the error. stating enums don't exist so that is why I am going to create a seperate file and access the enum.

Yes thats is exactly what I want to do is create an enum file for all my indicators
Last edited by ballboy11; 09-20-2017 at 06:13 AM.
ballboy11 is offline  
Reply With Quote
Old 09-20-2017, 02:11 PM   #8
NinjaTrader_AlanP
NinjaTrader Customer Service
 
NinjaTrader_AlanP's Avatar
 
Join Date: Apr 2016
Location: Denver, CO
Posts: 1,402
Thanks: 115
Thanked 280 times in 270 posts
Default

Hello ballboy11,

For an example of having an enum in one file and accessing it from another, I found a example at the following link,

http://ninjatrader.com/support/forum...07&postcount=1

Please let us know if you need further assistance.
NinjaTrader_AlanP is offline  
Reply With Quote
Old 09-22-2017, 07:38 AM   #9
ballboy11
Senior Member
 
Join Date: Jan 2016
Posts: 218
Thanks: 0
Thanked 6 times in 6 posts
Default

Thank you I finally got it to work I created a enum indicator and it works great now.
ballboy11 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Enumeration Operation - Issue # 11671 aligator Platform Technical Support 1 09-05-2017 07:50 AM
NT8b9 - new variation - collection was modified; enumeration may not execute sledge Version 8 Beta 1 03-21-2016 02:19 PM
Nt8-B5-Exception: collection was modified; enumeration operation may not execute sledge Version 8 Beta 2 02-25-2016 06:49 PM
Enumeration private scope impossible with "Properties" and Ninja generated Code rayko Indicator Development 3 11-14-2013 03:38 PM
Best Practices Question - Multiple Indicators across Multiple Timeframes pbailey19 Strategy Development 7 10-21-2013 08:14 AM


All times are GMT -6. The time now is 03:36 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content.