Thanks again.
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
Code problems
Collapse
X
-
Thank you Ray, that helped. Now I have only 1 error reported on this line. The error message reads "cannot apply indexing with [] to an expression of type double"...the little red error indicator is under the part where it reads "VarSto[1]"...any ideas?
Thanks again.
-
The error caused by the "scalar" has been cleared, however how do I insert the code to compile correctly so as to use the previous period value?
Could I define a value equal to VarSto[1] and simply insert that variable where needed in the script? Thanks again.
Comment
-
Or, if you wanted to store more than one bar back, so you can reference several bars back, you could create another dataseries...
Code:#region Variables private double VarSto = 0; private DataSeries myDataSeries2; private DataSeries VarStoSeries; #endregion protected override void Initialize() { ... myDataSeries2 = new DataSeries(this); VarStoSeries = new DataSeries(this); ... } protected override void OnBarUpdate() { if (CurrentBar < 3) return; // Make sure there are enough bars. if(CurrentBar < (Pr + (Pr * 1.5))){VarSto = StK;} else { myDataSeries2.Set(((1 - MyConst) * (VarStoSeries[3])) + (MyConst * Close)); VarSto = SMA(myDataSeries2, 2)[0]; } VarStoSeries.Set( VarSto ); }
Comment
-
As Josh has pointed out, you can use either technique, depending on how far back you want to access.
Keep in mind that using a DataSeies will use much, much more memory than just allocating a double, but the DataSeries will give you more possible functionality for the extra memory cost.
Don't use a screwdriver if what you really need is a chisel.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by JoMoon2024, Today, 06:56 AM
|
0 responses
6 views
0 likes
|
Last Post
by JoMoon2024
Today, 06:56 AM
|
||
Started by Haiasi, 04-25-2024, 06:53 PM
|
2 responses
17 views
0 likes
|
Last Post
by Massinisa
Today, 05:32 AM
|
||
Started by Creamers, Today, 05:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Creamers
Today, 05:32 AM
|
||
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
12 responses
1,786 views
0 likes
|
Last Post
by Leafcutter
Today, 05:30 AM
|
||
Started by poplagelu, Today, 05:00 AM
|
0 responses
3 views
0 likes
|
Last Post
by poplagelu
Today, 05:00 AM
|
Comment