public void test(double[] myBarsArray){
Print(myBarsArray[1].Count);
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Passing a BarsArray as a function parameter
Collapse
X
-
Hello swcooke,
Thank you for your post.
Are you getting an error when you try to compile this?
A BarsArray object would be of the type NinjaTrader.Data.Bars - not a double. Try this:
Please let us know if we may be of further assistance to you.Code:public void test(NinjaTrader.Data.Bars[] myBarsArray){ Print(myBarsArray[1].Count); }
-
I am getting an error. Here is my revised code and the error:
Error:Code:namespace NinjaTrader.NinjaScript.Indicators { public class MyCustomIndicator : Indicator { public void test(NinjaTrader.Data.Bars[] myBarsArray){ Print(myBarsArray[1].Count); } protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Enter the description for your new custom Indicator here."; Name = "MyCustomIndicator"; Calculate = Calculate.OnBarClose; IsOverlay = false; DisplayInDataBox = true; DrawOnPricePanel = true; DrawHorizontalGridLines = true; DrawVerticalGridLines = true; PaintPriceMarkers = true; ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right; //Disable this property if your indicator requires custom values that cumulate with each new market data event. //See Help Guide for additional information. IsSuspendedWhileInactive = true; } else if (State == State.Configure) { AddDataSeries("AAPL", new BarsPeriod {BarsPeriodType = BarsPeriodType.Day, Value = 1}, 30, "US Equities RTH", true); } else if (State == State.DataLoaded) { test(BarsArray[1]); } } } }
Code:[TABLE] [TR] NinjaScript File Error Code Line Column [/TR] [TR] [TD]MyCustomIndicator.cs[/TD] [TD]The best overloaded method match for 'NinjaTrader.NinjaScript.Indicators.MyCustomIndicator.test(NinjaTrader.Data.Bars[])' has some invalid arguments[/TD] [TD]CS1502[/TD] [TD]56[/TD] [TD]5[/TD] [/TR] [/TABLE] [TABLE] [TR] NinjaScript File Error Code Line Column [/TR] [TR] [TD]MyCustomIndicator.cs[/TD] [TD]Argument 1: cannot convert from 'NinjaTrader.Data.Bars' to 'NinjaTrader.Data.Bars[]'[/TD] [TD]CS1503[/TD] [TD]56[/TD] [TD]10[/TD] [/TR] [/TABLE]
Comment
-
You may be making things harder than necessary.Originally posted by swcooke View PostHow can I pass a specific BarsArray to a function? Here is what I am trying:
Code:public void test(double[] myBarsArray){ Print(myBarsArray[1].Count); }
My suggestion:
Don't pass the array. BarsArray is already global.
Pass the index instead.
then just call test(1) where '1' is index of the BarsArray you wish to print the Count of.Code:public void test(int index) { Print(BarsArray[index].Count); }
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
600 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
347 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
558 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
558 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment