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
Strategy errors
Collapse
X
-
Brett/Matthew,
As always, thanks for your prompt replies and for the assistance every way you can. I know how to call on the indicator values, just that in this case there are certain limitations doing it that way. Therefore, the example code that Matthew provided is very helpful.
-
Originally posted by 2Look4me View PostHello,
Instead of calling the Stochastics' values to be used in a strategy, I would like to copy and paste the entire Stochastics script.
How do I get around the error in "Properties": The name "Value" does not exist in the current context?
Thanks in advance...
Here is an example of the code used, where I replaced the public K and D value series with a private data series...I also attached an exported version
Code:public class StochStrategy : Strategy { #region Variables private int periodD = 7; // SlowDperiod private int periodK = 14; // Kperiod private int smooth = 3; // SlowKperiod private DataSeries den; private DataSeries nom; private DataSeries fastK; private DataSeries D; private DataSeries K; #endregion /// <summary> /// This method is used to configure the indicator and is called once before any bar data is loaded. /// </summary> protected override void Initialize() { den = new DataSeries(this); nom = new DataSeries(this); fastK = new DataSeries(this); D = new DataSeries(this); K = new DataSeries(this); } /// <summary> /// Calculates the indicator value(s) at the current index. /// </summary> protected override void OnBarUpdate() { nom.Set(Close[0] - MIN(Low, PeriodK)[0]); den.Set(MAX(High, PeriodK)[0] - MIN(Low, PeriodK)[0]); if (den[0].Compare(0, 0.000000000001) == 0) fastK.Set(CurrentBar == 0 ? 50 : fastK[1]); else fastK.Set(Math.Min(100, Math.Max(0, 100 * nom[0] / den[0]))); // Slow %K == Fast %D K.Set(SMA(fastK, Smooth)[0]); D.Set(SMA(K, PeriodD)[0]); Print(K[0]); } #region Properties /// <summary> /// </summary> [Description("Numbers of bars used for moving average over K values")] [GridCategory("Parameters")] public int PeriodD { get { return periodD; } set { periodD = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Numbers of bars used for calculating the K values")] [GridCategory("Parameters")] public int PeriodK { get { return periodK; } set { periodK = Math.Max(1, value); } } /// <summary> /// </summary> [Description("Number of bars for smoothing the slow K values")] [GridCategory("Parameters")] public int Smooth { get { return smooth; } set { smooth = Math.Max(1, value); } } #endregion }
Attached Files
Leave a comment:
-
I would not advise copy and pasting the stochastics code in to your strategy. You should call it like a regular indicator in the strategy. Why do you want to copy/paste vs call like normal indicator? If you do not know how to call it as normal (without copy/paste) then let me know I could furnish information to help you get started with that.
Leave a comment:
-
Strategy errors
Hello,
Instead of calling the Stochastics' values to be used in a strategy, I would like to copy and paste the entire Stochastics script.
How do I get around the error in "Properties": The name "Value" does not exist in the current context?
Thanks in advance...Tags: None
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rhyminkevin, Today, 04:58 PM
|
3 responses
46 views
0 likes
|
Last Post
by Anfedport
Today, 05:24 PM
|
||
Started by iceman2018, Today, 05:07 PM
|
0 responses
5 views
0 likes
|
Last Post
by iceman2018
Today, 05:07 PM
|
||
Started by lightsun47, Today, 03:51 PM
|
0 responses
7 views
0 likes
|
Last Post
by lightsun47
Today, 03:51 PM
|
||
Started by 00nevest, Today, 02:27 PM
|
1 response
14 views
0 likes
|
Last Post
by 00nevest
Today, 03:48 PM
|
||
Started by futtrader, 04-21-2024, 01:50 AM
|
4 responses
49 views
0 likes
|
Last Post
by futtrader
Today, 03:01 PM
|
Leave a comment: