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 04-14-2008, 08:25 AM   #1
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Smile New here - How to subtract two Indicators?

Hi everyone,

Just installed NJ and loving it.

I tried to build a simple custom indicator, based on the difference of two RSI (on different length), but I cannot build it using the double function:
double RS1 = RSI...
double RS2 = RSI...
double diff = RS1 - RS2

I get "Cannot implicitly convert type Ninjatrader.Indicator.RSI to double CS0029.

I understand I cannot use double to subtract two indicators, but how am I supposed to do?

Thank you everyone for help
stefy is offline  
Reply With Quote
Old 04-14-2008, 08:29 AM   #2
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

Unfortunately this is not supported. You would need to implement a custom indicator which subtracts these values data point by data point and stuffs the result in its own plot/data series.
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-14-2008, 08:37 AM   #3
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_Dierk View Post
Unfortunately this is not supported. You would need to implement a custom indicator which subtracts these values data point by data point and stuffs the result in its own plot/data series.
Thank you NJ_Dierk

Could you explain (with an example or with a similar indicator) how to do that?
Otherwise I don't think I will manage to move forward...
stefy is offline  
Reply With Quote
Old 04-14-2008, 08:39 AM   #4
NinjaTrader_Dierk
Administrator
 
NinjaTrader_Dierk's Avatar
 
Join Date: Mar 2005
Location: Bamberg, Germany
Posts: 9,994
Thanks: 0
Thanked 6 times in 6 posts
Default

I suggest ripping through our indicator code samples and the references and tips here:
http://www.ninjatrader-support.com/v...splay.php?f=30
http://www.ninjatrader-support.com/v...splay.php?f=31
NinjaTrader_Dierk is offline  
Reply With Quote
Old 04-14-2008, 10:03 AM   #5
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

Following the tutorials:

1) I introduced the variables:
#region Variables

private DataTimeSeries RSI1;
DataTimeSeries RSI2;

#endregion

2) I declared the variables:

RSI1.Set(RSI(...));
RSI2.Set(RSI(...));
RSI1 = new DateTimeSeries(this);
RSI2 = new DateTimeSeries(this);

double diff = RSI1 - RSI2;


Yet, it doesn't work!

Who can help me with an example?

Thank you everyone
stefy is offline  
Reply With Quote
Old 04-14-2008, 10:17 AM   #6
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Please import the attached via Files > Utilities and review the source code.
Attached Files
File Type: zip SampleDataSeries.zip (1.6 KB, 17 views)
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-15-2008, 02:33 PM   #7
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you, Ray, but it doesn't work yet!
#region Variables
private DataSeries mySeries1;
DataSeries mySeries2;
#endregion

mySeries1 = new DataSeries(this);
mySeries2 = new DataSeries(this);

protected override void OnBarUpdate()
{
double myValue1 = RSI(Close, x, y);
double myValue2 = RSI(Close, x, z);
mySeries1.Set(myValue1);
mySeries2.Set(myValue2);
double Diff = myValue1 - myValue2;
Plot0.Set(Diff);
}


Please anyone can tell me what's wrong? I'm spending sooooooo much time on it, I'm getting desperate!
stefy is offline  
Reply With Quote
Old 04-15-2008, 02:41 PM   #8
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Try this:

protected override void OnBarUpdate()
{
double myValue1 = RSI(Close, x, y)[0];
double myValue2 = RSI(Close, x, z)[0];
mySeries1.Set(myValue1);
mySeries2.Set(myValue2);
double Diff = myValue1 - myValue2;
Plot0.Set(Diff);
}

however, what you are doing is redundant, I would do this and skip using any DataSeries object:

protected override void OnBarUpdate()
{
Plot0.Set(RSI(Close, x, y)[0] - RSI(Close, x, z)[0]);
}
NinjaTrader_Ray is offline  
Reply With Quote
Old 04-15-2008, 02:59 PM   #9
stefy
Senior Member
 
Join Date: Apr 2008
Posts: 310
Thanks: 0
Thanked 0 times in 0 posts
Default

I finally generated the indicator (using the latter expression you suggested), but I get a 0 flat line as indicator. Why?

Thank you
stefy is offline  
Reply With Quote
Old 04-15-2008, 03:12 PM   #10
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,164
Thanks: 6
Thanked 46 times in 32 posts
Default

Since the value of the calculation is likely zero. You will need to debug it.

Here is some guidance - http://www.ninjatrader-support.com/v...ead.php?t=3418
NinjaTrader_Ray 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
we need indicators !!! Elmi Indicator Development 77 07-25-2012 10:15 AM
new indicators JAY526 Charting 28 12-19-2011 03:19 PM
Charting indicators using other indicators as the input Elliott Wave Charting 3 04-04-2008 03:54 PM
Subtract an indicator snake Strategy Development 1 06-06-2007 02:22 PM
TTM Indicators Freddie Indicator Development 1 03-11-2007 06:28 AM


All times are GMT -6. The time now is 05:32 PM.