Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Setting an internal Array as variable
Collapse
X
-
The simplest, quickest and final solution to my requirement is using a traditional ARRAY.
Here, all the basic steps done in order to be able to work properly as needed
1. Declaring ARRAY
#region Variables
double[] acu = new double[initial];
#endregion
2. Updating the Array dimension that actually will be used
protected override void OnStartUp()
{
acu = new double[oscillation+1];
}
3. After use if "reseting or clearing" the Array is needed, then proceed with:
Array.Clear(acu, 0, wpoint.Length);
-
Originally posted by koganam View PostThe point of OOP is that objects are independent entities that contain their data and the methods to manipulate said data. The Bars object cannot interfere with assignations to a different object. Resolve your indexing issue, based on the object that is being indexed.
Your issue is assigning data to an index that does not exist. That is the only issue that you need to resolve in this case. Unfortunately, the error message that you are getting is very generic, and could relate to anything that is indexed and to which you are referring. Your desire for secrecy if understandable, but if you really want a resolution, you are probably going to have to reveal everything that relates to this part of your code.- What is "t", for example?
- How big is it?
- Is it a fixed size?
- What is the capacity of your List? If you have not defined its capacity, direct assignation can be problematic: Use List.Add() or List.Insert(), which are the standard way of adding elements to a List.
And you are still going to have to ensure that the Close index to which you refer is valid.
Once again, thanks
Best of luck Pal
Leave a comment:
-
Originally posted by pstrusi View PostThanks Koganam, yes, I'm aware of that minimum necessary condition but it's not the cause of the runtime error. It seems instead that the NT internal Dataseries of prices doesn't make possible to assign values to out-of-sync List variable. The way I'm working this is with some kind adding dimensional variable set of data.
Your issue is assigning data to an index that does not exist. That is the only issue that you need to resolve in this case. Unfortunately, the error message that you are getting is very generic, and could relate to anything that is indexed and to which you are referring. Your desire for secrecy if understandable, but if you really want a resolution, you are probably going to have to reveal everything that relates to this part of your code.- What is "t", for example?
- How big is it?
- Is it a fixed size?
- What is the capacity of your List? If you have not defined its capacity, direct assignation can be problematic: Use List.Add() or List.Insert(), which are the standard way of adding elements to a List.
And you are still going to have to ensure that the Close index to which you refer is valid.
Leave a comment:
-
Thanks Koganam, yes, I'm aware of that minimum necessary condition but it's not the cause of the runtime error. It seems instead that the NT internal Dataseries of prices doesn't make possible to assign values to out-of-sync List variable. The way I'm working this is with some kind adding dimensional variable set of data.
Leave a comment:
-
Originally posted by pstrusi View PostSomething like this dumb example:
Code:for ( int d = 1; d <= t; d++ ) { if ( Close[0]-Close[d] > 0 ) { Listb[d]=1; } } Then other calculations
Leave a comment:
-
The problem is the Bars object index of NT that interferes with that way to assign values to a List array variable, thus maybe the solution is to create manually vertical dimensions through others procedures, without altering the original index.
Leave a comment:
-
Thank you very much Calonious for your help, very useful. Yes, I'll have to think better how to work at the same time with sync and out-of-sync series for certain calculations in an efficient way, it's obvious that I got this wrong.
Regards
Leave a comment:
-
Pstrusi,
This is the exact opposite how DataSeries will work. Essentially, if you don't set a value for that bar update, the DataSeries will replace it with 0, or Close[0] price( I don't remember which off the top of my head) for that bar.
Since you have now created this out of sync series, or async series if you will, you need to insert your own indexes.
The great thing about .Insert() is that it handles the shifting of the other indexes appropriately like with the DataSeries.Set()
https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx
Exampe -
Instead of this
Listb[d]=1;
try this
Listb.Insert(0, 1)
Also, ensure that you do have enough data for your loop call for the Close[d] prices.
Leave a comment:
-
-
Originally posted by Calonious View PostWhat exactly are you doing in your For Loop?
Also, remember that this error means that any items you are indexing, AKA using [value], the value is too big. Meaning that index value is larger than the actual collection size you are trying to access
Leave a comment:
-
Originally posted by pstrusi View PostHow to address this issue ?
Within a loop, I must use the variable Close[0] and at the same time, assigning a certain value to a List array variable. Despite all is well declared previously, and it compiles flawlessly, when it comes to act, a runtime error appears:
Error on calling 'OnBarUpdate' method for strategy 'QWS/d86de07fec8c46148c329c5d2a13fd08': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Obviously is cause I'm trying to use Close[0] object with a List array variable at the same time. How to declare properly variables, procedures...etc in order to avoid "interference" and being able to run the script?
Here is the structure of the script:
Code:namespace NinjaTrader.Strategy { /// <summary> /// Q /// </summary> using System.Collections.Generic; [Description("Q")] public class QWS : Strategy { #region Variables // all variables here #endregion List<int> cable = new List<int>(); protected override void Initialize() { SetStopLoss("", CalculationMode.Ticks, pnllimit, false); CalculateOnBarClose = true; BarsRequired=31; DisconnectDelaySeconds = 130; MaxRestartMinutes = 30; MaxRestartAttempts = 120; ConnectionLossHandling = ConnectionLossHandling.KeepRunning ; RestartDelaySeconds = 2; } protected override void OnPositionUpdate(IPosition position) { // do my stuff } protected override void OnBarUpdate() { if ( Bars.BarsSinceSession<= BarsRequired ) { return; } for ( int d = 1; d <= t; d++ ) { // do calculations using Close[0] and assign values to List Array } if( A) { EnterLong(qty); } if( B) { EnterShort(qty); } } protected override void OnTermination() { // Do final }
Also, remember that this error means that any items you are indexing, AKA using [value], the value is too big. Meaning that index value is larger than the actual collection size you are trying to access
Leave a comment:
-
How to address this issue ?
Within a loop, I must use the variable Close[0] and at the same time, assigning a certain value to a List array variable. Despite all is well declared previously, and it compiles flawlessly, when it comes to act, a runtime error appears:
Error on calling 'OnBarUpdate' method for strategy 'QWS/d86de07fec8c46148c329c5d2a13fd08': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
Obviously is cause I'm trying to use Close[0] object with a List array variable at the same time. How to declare properly variables, procedures...etc in order to avoid "interference" and being able to run the script?
Here is the structure of the script:
Code:namespace NinjaTrader.Strategy { /// <summary> /// Q /// </summary> using System.Collections.Generic; [Description("Q")] public class QWS : Strategy { #region Variables // all variables here #endregion List<int> cable = new List<int>(); protected override void Initialize() { SetStopLoss("", CalculationMode.Ticks, pnllimit, false); CalculateOnBarClose = true; BarsRequired=31; DisconnectDelaySeconds = 130; MaxRestartMinutes = 30; MaxRestartAttempts = 120; ConnectionLossHandling = ConnectionLossHandling.KeepRunning ; RestartDelaySeconds = 2; } protected override void OnPositionUpdate(IPosition position) { // do my stuff } protected override void OnBarUpdate() { if ( Bars.BarsSinceSession<= BarsRequired ) { return; } for ( int d = 1; d <= t; d++ ) { // do calculations using Close[0] and assign values to List Array } if( A) { EnterLong(qty); } if( B) { EnterShort(qty); } } protected override void OnTermination() { // Do final }
Last edited by pstrusi; 04-16-2015, 03:18 PM.
Leave a comment:
-
You won't have any issues. Its just telling the script to use this library so that you can use the List<> class and so forth.
Go ahead and add using System.Collections.Generic; to the "Using Declarations" region
Leave a comment:
-
I have another technical consult. As you've previously said well, using "List" is even better than ArrayList in performance, so I decide to use "List". But now I read that above the top you must put this first:
using System.Collections.Generic; so my doubt is, since it goes from the top, could it interfere with the usual behavior of a NinjaScript variables? I imagine NOT, but all this area of COLLECTIONS is quite new for me
Leave a comment:
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
31 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
2 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,281 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
||
Started by WHICKED, Today, 12:45 PM
|
2 responses
19 views
0 likes
|
Last Post
by WHICKED
Today, 03:36 PM
|
||
Started by Tim-c, Today, 02:10 PM
|
1 response
10 views
0 likes
|
Last Post Today, 02:52 PM |
Leave a comment: