NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Indicator Development

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

Reply
 
Thread Tools Display Modes
Old 11-01-2008, 12:38 AM   #1
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default Integer Output

I have an indicator which needs to output an integer to strategies.


I tried an IntSeries, but am having errors with the following property;

[Browsable(false)]
[XmlIgnore()]
public IntSeries GridValue
{
get { return gridValue[1]; }// error here
}


EDIT: I am receiving an error which states 'Cannot implicitly convert int to NinjaTrader.Data.IntSeries'.


How else can I output an integer value from an indicator without it being 'set' as above, so its value may be used within Strategies ??
Last edited by Faspomy; 11-01-2008 at 09:31 AM.
Faspomy is offline  
Reply With Quote
Old 11-01-2008, 10:47 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

I suspect 'gridValue' is in fact your IntSeries? If yes, then:

return gridValue;

is sufficient. If you want to return the actual integer value and not the series, then change to:

public int GridValue
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-01-2008, 11:31 AM   #3
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

Thank you Ray.


I'm not sure what you mean by " If you want to return the actual integer value and not the series, then change to: public int GridValue"

Will a series allow me to read integer values set by the indicator ? For example;

PHP Code:
if (SMA(14).Value[0] > SMA(14).Value[1])
            {
                
gridValue.Set(20);
            } 
I would like to access the '20' in a strategy.

When I create a public int, the value is browsable, and is pre-set within the indicator's properties. Example; MyIndicator(GridValue, period)

How can I gain access to GridValue's output from the indicator, without having its value pre-set as above ?
Last edited by Faspomy; 11-01-2008 at 12:48 PM.
Faspomy is offline  
Reply With Quote
Old 11-01-2008, 02:51 PM   #4
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

gridValue is a series of values, an array for arguments sake. If you want to expose the entire array, then

return gridValue;

if you only want to return the current bar value held by the gridValue series, then

public int GridValue
NinjaTrader_Ray is offline  
Reply With Quote
Old 11-02-2008, 05:58 PM   #5
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

Thank you Ray.
I changed to an integer

PHP Code:
 [Browsable(false)]  
        [
XmlIgnore()]        
        public 
int GridValue
        
{
            
get {return gridValue; } 
Still having a problem accessing the data, though. Here are conditions within the indicator to set gridValue;

PHP Code:
             SMA1.Set(SMA(14).Value[0]);
            
SMA2.Set(SMA(7).Value[0]);
            
             if (
CrossAbove(SMA(14).Value,SMA(7).Value1));
            {
                
gridValue 10;
                Print(
"gridValue = 10");

            }
            
            if (
CrossAbove(SMA(7).Value,SMA(14).Value1));
            {
                
gridValue 20;
                Print(
"gridValue = 20");
            } 
This is the Strategy code to read the value;

PHP Code:
           if (MyIndicator(1).GridValue == 10)
            {
                
EnterLong(1"");
            }
            
            if (
MyIndicator(1).GridValue == 20)
            {
                
ExitLong();
            } 
What should happen is obvious. However, nothing happens-- no buys or sells are activated.

Also, I am receiving "gridValue = 10" & " gridValue = 20" printing-out to the output window, at the same time, on every bar.

Questions;
- am I formatting the integer correctly in the indicator ?
- do conditionals work differently in an indicator versus a strategy ? If not, why would I be receiving erroneous results ?
Last edited by Faspomy; 11-02-2008 at 08:00 PM.
Faspomy is offline  
Reply With Quote
Old 11-03-2008, 09:31 AM   #6
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,

This link has a reference sample that shows how to make a variable exposed:
http://www.ninjatrader-support.com/v...ead.php?t=4991

Notice what is going on in the Properties area and how Update() is used.
NinjaTrader_Ben is offline  
Reply With Quote
Old 11-03-2008, 09:59 AM   #7
Faspomy
Senior Member
 
Join Date: Oct 2008
Location: US&A
Posts: 115
Thanks: 0
Thanked 1 time in 1 post
Default

Ban,

thank you. That should solve the update problem.

I am still having a problem, though, with the values being printed-out to the output window as both '20' and '10' on each bar.

Am I missing something ?
Faspomy is offline  
Reply With Quote
Old 11-03-2008, 10:32 AM   #8
NinjaTrader_Ben
NinjaTrader Customer Service
 
NinjaTrader_Ben's Avatar
 
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
Default

Hello,


Try removing the ";" after each condition and see if it works better.

Also you do not need to use SMA(14).Value and SMA(7).Value. Do it this way:

if (CrossAbove(SMA(14), SMA(7), 1))
{
gridValue = 10;
Print(“gridValue = 10”);
}

NinjaTrader_Ben 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
Not integer thresholds for indicators stefy Strategy Development 2 06-12-2008 02:42 PM
dataseries integer values? Burga1 General Programming 5 04-09-2008 08:53 PM
Prevent NT to round EMA value to integer Nick88 Charting 3 03-10-2008 08:39 AM
Rounding off to an integer? Burga1 General Programming 1 01-02-2008 10:20 PM
error combining ema with an integer Thomas Strategy Development 3 08-16-2007 05:40 AM


All times are GMT -6. The time now is 06:02 PM.