NinjaTrader Support Forum  
X

Attention!

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


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 07-12-2009, 06:13 PM   #1
scyche
Junior Member
 
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default how to keep one dateseries unchanged?

hi, I created a indicator, which used two dataseries. One is the close price, the other is chosen when using the indicator for the strategy. But, when I input RSI or CCI when creating a new strategy with this indicator, the close price is replaced with the RSI or CCI during calculation. What should I do if I want the close price keep unreplaced?

Thank you very much!
scyche is offline  
Reply With Quote
Old 07-12-2009, 06:24 PM   #2
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,

Do you mean the RSI and CCI are replaced with the close value? If so, that is the default when a value is not found. I suggest posting some code snippets and let us give you some pointers.
NinjaTrader_Ben is offline  
Reply With Quote
Old 07-12-2009, 07:57 PM   #3
scyche
Junior Member
 
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

No, it's not replaced by close price. Following is part of my code:

if((Input[1]-Input[date2])/Input[date2]>=0.1&&Close[date2]>Close[1])
{test=1;}

When I'm building a strategy, I put "RSI(14)" in Input box. I guess when calculating, the "Input[]" should be replaced by "RSI(14)[]". But the "Close[]" here is also replaced by "RSI(14)[]", which is not expected. What should I do to keep "Close[]" unchanged?
scyche is offline  
Reply With Quote
Old 07-13-2009, 05:43 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

This is expected as both parts respond to your date2 input paramter in the snipped you posted, so best would be to use a new input for the second part of your snippet.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-13-2009, 06:13 PM   #5
scyche
Junior Member
 
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

I have tried to replace Close[date2] with Close[date22], in which date22 it just equal to date2. But the system still use the input dataseries to substitute the close price. Do you have any other suggestions?
scyche is offline  
Reply With Quote
Old 07-14-2009, 05:48 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

scyche, as explained in your other thread, Input refer to the main input series used for the indicator calculations, this will be Close per default if you don't set PriceTypeSupported to true in Initialize() - for your use create a new data series object for your RSI or just use the RSI(14) directly in the code like -

Code:
 
if (Input[1] - RSI(14, 1)[date2] > 0)
{do your thing}
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-14-2009, 02:30 PM   #7
scyche
Junior Member
 
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you for your suggestion. My problem is that, I need to use two dataseries in my calculation. One is an indicator, RSI, CCI, EMA, whatever. The other is close price. I want use the former one as my main input, so I think I can use Input[] in stead of those indicators. But for close prices, I want them to be constant no matter what my input is. But the problem is that it seems the close price is changing accordingly. I have tried to create a new dataseries to contain the close price. But when I use "AAA.Set=Close[0]", AAA actually equals to my main input - for the close prices are already changed.

Do you have some other ideas? I would be very happy to have a try!

Thank you very much!
scyche is offline  
Reply With Quote
Old 07-15-2009, 05:16 AM   #8
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
Default

scyche, sorry don't really follow you - if you want it to be constant, just hard code it in to always use the Close, there's then no need to feed this into a separate dataseries, as it already is a dataseries object by default. Best would be you post the full updated code you use now, so we can take a look.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 07-15-2009, 10:48 AM   #9
scyche
Junior Member
 
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
Default

Thank you very much! Here's my code.

public class Compareslopes : Indicator
{
#region Variables

private int n = 1;
#endregion


protected override void Initialize()
{
CalculateOnBarClose = true;
Overlay= true;
PriceTypeSupported = false;
}



protected override void OnBarUpdate()
{
int i=0;
int j=0;
int k=0;
int l=0;
int m=0;
double temp0=0;
double temp1=0;
double temp2=0;
int date=0;
int date2=0;
int date3=0;
int[] tops;
int test=0;
tops = new int[50];

if(CurrentBar<=n)
return;
else

{
date=HighestBar(Input, n-1);
for(i=n-2;i>=0;i--)
{
if(Input[i+1]-Input[i+2]>=0&&Input[i+1]-Input[i]>=0)
{
tops[j]=i+1;

if(tops[j]==date)
m=j;

j++;
}
}


if(date == 1)
{
if(date<tops[0])
{
temp1=Slope(Input, tops[0], 1);
date2=tops[0];
for(k=0;k<j-1;k++)
{
if(Slope(Input, tops[k], date)<temp1)
{
temp1=Slope(Input, tops[k], 1);
date2=tops[k];
}
}

if((Input[1]-Input[date2])/Input[date2]>=0.1&&Close[date2]>Close[1])
test=1;
}

}

else
{
if (tops[0]==0||date==0||date==1)
{;}
else
{
if(date>tops[j-1]&&tops[j-1]==1)
{
temp2=Slope(Input, date, 1);

for(l=m+1;l<=j-1;l++)
{
if(Slope(Input, date, tops[l])>temp2)
date3=1;

}

if(date3==0&&(Input[date]-Input[1])/Input[1]>=0.1&&Close[1]<Close[date])
test=-1;
}
}
}
}
Value.Set(test);
}
Last edited by scyche; 07-15-2009 at 10:50 AM.
scyche is offline  
Reply With Quote
Old 07-15-2009, 11:23 AM   #10
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

scyche, while Bertrand is away, I'll toss in a comment. When he gets back he'll add something if necessary.

Can you try replacing all the Input[] with the value you actually want? For example if you want to use close prices, use Close[0]. If you want to use RSI, use RSI(14, 1)[0].

Sometimes when using Input for everything, the value that comes from Input isn't what you expect it to be.
Last edited by NinjaTrader_Austin; 07-15-2009 at 11:27 AM.
NinjaTrader_Austin 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
Advancing, declining, unchanged issues eleven Connecting 1 05-25-2009 04:14 AM


All times are GMT -6. The time now is 10:06 AM.