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

Enum Declarations

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

    #16
    I've deleted the sample reference indicator which had the same name in the global namespace and added the changes but still have some compile errors.



    Code:
    #region Using declarations
    using System;
    using System.ComponentModel;
    using System.Diagnostics;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Data;
    using NinjaTrader.Indicator;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Enter the description of your strategy here
        /// </summary>
        [Description("Enter the description of your strategy here")]
        public class FTRUniversal : Strategy
        {
            #region Variables
          private UniversalMovingAverage	matype	= UniversalMovingAverage.SMA;
    		private int				period	= 14;
            #endregion
    
            /// <summary>
            /// This method is used to configure the strategy and is called once before any strategy method is called.
            /// </summary>
            protected override void Initialize()
            {
                CalculateOnBarClose = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
    			
    		switch (matype)
    {
    case _UniversalMovingAverageEnums.UniversalMovingAverage.HMA:
    {
    //set stop loss based on HMA value
    SetStopLoss(HMA(20));
    }
    }
    
            }
    
            #region Properties
            		// Creates the user definable parameter for the moving average type.
    		[Description("Choose a Moving Average type.")]
    		[Category("Parameters")]
    		public UniversalMovingAverage MAType
    		{
    			get { return matype; }
    			set { matype = value; }
    		}
    		
    		[Description("Numbers of bars used for calculations")]
    		[Category("Parameters")]
    		public int Period
    		{
    			get { return period; }
    			set { period = Math.Max(1, value); }
    		}
            #endregion
        }
    } 
    namespace _UniversalMovingAverageEnums
    {
    
    public enum UniversalMovingAverage
    {
    EMA,
    HMA,
    SMA,
    WMA
    }
    }

    Comment


      #17
      Hello brucelevy,

      Thanks for your reply.

      Please use the HMA overload that includes the bars ago reference:
      SetStopLoss(HMA(20)[0]);

      Additionally, you need to call UniversalMovingAverage from the _UniversalMovingAverageEnums namespace where it resides like so:
      public _UniversalMovingAverageEnums.UniversalMovingAverag e matype = _UniversalMovingAverageEnums.UniversalMovingAverag e.SMA;

      the same in your case:
      case _UniversalMovingAverageEnums.UniversalMovingAverag e.HMA:
      {
      SetStopLoss(HMA(20)[0]);
      break;
      }

      You will need to include the break after all necessary actions are executed so that control can be transferred outside of the switch statement or to another case label.

      Please let me know if I may be of any further assistance.
      Alan S.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by XXtrader, Yesterday, 11:30 PM
      2 responses
      11 views
      0 likes
      Last Post XXtrader  
      Started by Waxavi, Today, 02:10 AM
      0 responses
      6 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by TradeForge, Today, 02:09 AM
      0 responses
      11 views
      0 likes
      Last Post TradeForge  
      Started by Waxavi, Today, 02:00 AM
      0 responses
      2 views
      0 likes
      Last Post Waxavi
      by Waxavi
       
      Started by elirion, Today, 01:36 AM
      0 responses
      7 views
      0 likes
      Last Post elirion
      by elirion
       
      Working...
      X