![]() |
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 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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! |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: May 2008
Location: Denver, CO
Posts: 3,157
Thanks: 0
Thanked 3 times in 3 posts
|
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.
Ben
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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?
|
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
|
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}
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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! |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,382
Thanks: 252
Thanked 967 times in 950 posts
|
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.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: Jul 2009
Posts: 15
Thanks: 0
Thanked 0 times in 0 posts
|
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.
|
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
|
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.
Austin
NinjaTrader Customer Service
Last edited by NinjaTrader_Austin; 07-15-2009 at 11:27 AM.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Advancing, declining, unchanged issues | eleven | Connecting | 1 | 05-25-2009 04:14 AM |