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!
See more
See less

Partner 728x90

Collapse

Strategy errors

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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...

    #2
    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.

    Comment


      #3
      Originally posted by 2Look4me View Post
      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...
      "Value" is a data series that is added when you use the Add() method for indicator plots.... this method does not work from a Strategy, so there is no Value series for you to use. You will have to replace it with your own custom data series.



      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
      MatthewNinjaTrader Product Management

      Comment


        #4
        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.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Balage0922, Today, 07:38 AM
        0 responses
        2 views
        0 likes
        Last Post Balage0922  
        Started by JoMoon2024, Today, 06:56 AM
        0 responses
        6 views
        0 likes
        Last Post JoMoon2024  
        Started by Haiasi, 04-25-2024, 06:53 PM
        2 responses
        19 views
        0 likes
        Last Post Massinisa  
        Started by Creamers, Today, 05:32 AM
        0 responses
        6 views
        0 likes
        Last Post Creamers  
        Started by Segwin, 05-07-2018, 02:15 PM
        12 responses
        1,786 views
        0 likes
        Last Post Leafcutter  
        Working...
        X