Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

SampleMACrossOver not working

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

    SampleMACrossOver not working

    Hi,

    The SampleMACrossOver Strategy is not working
    on my NT7.18 Beta as you can see in the attachment.
    The code is below.
    What can I do?

    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.Strategy;
    #endregion
    
    // This namespace holds all strategies and is required. Do not change it.
    namespace NinjaTrader.Strategy
    {
        /// <summary>
        /// Simple moving average cross over strategy.
        /// </summary>
        [Description("Simple moving average cross over strategy.")]
        public class SampleMACrossOver : Strategy
        {
            #region Variables
            private int        fast    = 10;
            private int        slow    = 25;
            #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()
            {
                SMA(Fast).Plots[0].Pen.Color = Color.Orange;
                SMA(Slow).Plots[0].Pen.Color = Color.Green;
    
                Add(SMA(Fast));
                Add(SMA(Slow));
    
                CalculateOnBarClose    = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick).
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CrossAbove(SMA(Fast), SMA(Slow), 1))
                    EnterLong();
                else if (CrossBelow(SMA(Fast), SMA(Slow), 1))
                    EnterShort();
            }
    
            #region Properties
            /// <summary>
            /// </summary>
            [Description("Period for fast MA")]
            [GridCategory("Parameters")]
            public int Fast
            {
                get { return fast; }
                set { fast = Math.Max(1, value); }
            }
    
            /// <summary>
            /// </summary>
            [Description("Period for slow MA")]
            [GridCategory("Parameters")]
            public int Slow
            {
                get { return slow; }
                set { slow = Math.Max(1, value); }
            }
            #endregion
        }
    }
    Attached Files

    #2
    Hello cbaer,

    You will need to set 'Enabled' to True for the strategy to start working. The screenshot displays this is not the case on your end, since it reflects a (D). You can set 'Enabled' in the strategy parameters window that appears when you inititate a strategy.

    Let me know if this will not work for you.

    Comment


      #3
      Hello Jason,

      This problem is resolved. Thanks!

      cbaer

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      599 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      345 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      558 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      558 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X