I am building the code for an indicator and am passing a custom data series as a parameter to a custom function. Unfortunately only the current calue of the series (i.e MySeries{0}) is being passed but not the previous series values - i.e. I can access MySeries[1] in the main but in the function the value of MySeries[1] is zero. The MySeries[0] value is correct in the main as well as in the function. Can you please provide a suggestion as to how I can pass an entire custom series as a parameter to a function? Any suggestions would be greatly appreciated. Thank you.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Data Series as Parameters to Functions
Collapse
X
-
Data Series as Parameters to Functions
HI,
I am building the code for an indicator and am passing a custom data series as a parameter to a custom function. Unfortunately only the current calue of the series (i.e MySeries{0}) is being passed but not the previous series values - i.e. I can access MySeries[1] in the main but in the function the value of MySeries[1] is zero. The MySeries[0] value is correct in the main as well as in the function. Can you please provide a suggestion as to how I can pass an entire custom series as a parameter to a function? Any suggestions would be greatly appreciated. Thank you.Tags: None
-
Hi Zeos6,
What you can do is move your function to its own indicator script. You can then pass in a data series as parameter. Otherwise you can build a function accepting DataSeries as input.Last edited by NinjaTrader_RyanM1; 06-09-2011, 01:40 PM.Ryan M.NinjaTrader Customer Service
-
Hi Ryan,
Thanks for the reply. Wow, this seems like a very clunky approach - to build a new indicator just to hold custom series values. If a series can be an input to an indicator why can it not be an input to a method? I can understand that perhaps you don't want it to be a value type input but how about a pointer or a reference? Is this perhaps the approach taken to allow series to be inputs to other series and indicators?
Comment
-
You can pass a DataSeries to a function, and get the correct values from the passed series. It all depends on how the function is written. Unfortunately, that means that I would have to see the function implementation, before I could possibly see what might not be quite kosher.Originally posted by Zeos6 View PostHi Ryan,
Thanks for the reply. Wow, this seems like a very clunky approach - to build a new indicator just to hold custom series values. If a series can be an input to an indicator why can it not be an input to a method? I can understand that perhaps you don't want it to be a value type input but how about a pointer or a reference? Is this perhaps the approach taken to allow series to be inputs to other series and indicators?
Comment
-
Yes, it is possible besides creating a separate indicator. You just have to build the function accepting DataSeries as input. Thanks for the reply and hopefully this example helps you out.
public int myCustomMethod (DataSeries myDataSeries)
{
if (myDataSeries[0] > 0)
return 1;
else
return 0;
}
Last edited by NinjaTrader_RyanM1; 06-09-2011, 01:44 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Hi Koganam,
The calling statemnet in OnBarUpdate() is:
if (fastAverageType == FastAverageTypes.fastEMA) fastAverage_Down.Set(EMA(trailingStopInputSeries, fastAveragePeriod)[0]);
double? tStop = TDown(fastAverage_Down, slowAverage_Down);
The function is:
private double? TDown(DataSeries fastAverage, DataSeries slowAverage)
{
//find previous values of fast moving average
double fastAvg = fastAverage[0];
double fastAvg1 = fastAverage[1];
double fastAvg3 = fastAverage[3];
double fastAvg5 = fastAverage[5];
...
}
Thanks for your help.
Comment
-
Our support for this is limited -- This is more C# than NinjaScript. My suspicion is there is an issue with the return type you're expecting for this method. You're returning a double, which is only one value. If you need to return a series of values, would have to look into a different type, like a list.
If you aren't really producing a value from the method, but want a routine to assign values, look at structuring as void.Last edited by NinjaTrader_RyanM1; 06-09-2011, 02:44 PM.Ryan M.NinjaTrader Customer Service
Comment
-
Something seems to be wrong with your method's signature, at the very least.
seems incorrect.Code:private double? TDown(DataSeries fastAverage, DataSeries slowAverage)
Correct would be:
I am actually a bit surprised that what you had even compiled at all.Code:private double? TDown([COLOR="Red"][B]I[/B][/COLOR]DataSeries fastAverage, [COLOR="red"][B]I[/B][/COLOR]DataSeries slowAverage)
ref: http://www.ninjatrader.com/support/h...dataseries.htmLast edited by koganam; 06-09-2011, 07:24 PM.
Comment
-
Hi Koganam,
Thanks for your reply. It is appreciated. The signature of the function seems correct. The question I have based on what you posted is whether I need to use DataSeries or IDataSeries in the function. I declare the custom series as DataSeries in Variables and I initialize them in Initialize(). I have tried to use IDataSeries and although I can declare them in Variables, I cannot create a new instance of them in Initialize (I get an error on compilation). So, do you declare and initialize as DataSeries and in the function use IDataSeries? The way I have it now is that I use DataSeries everywhere and it seems to be working fine.
On a side note, the thread was initially posted on the basis of whether one can obtain past values of a custom series in a custom function. The answer is yes and I have found my error. It turns out that you need to load the appropriate number of bars first to calculate all the parameters required by the custom series. I am creating a custom price type series as well for the custom average series and I was not loading sufficent number of bars to have the custom price type data available to perform the calculation so my values were coming out as 0.
Any clarification of when and how to use IDataSeries you may be able to provide would be greatly appreciated. Thank you very much.
P.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
598 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
343 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
557 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
555 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment