Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Complete Program with the extras

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

    Complete Program with the extras

    I am very new to Ninja Script and C#. I have a strategy and have found much help in the forum, however there are a few things I do not understand.
    What are all the nec parts to make the program work? I have seen #Region, namespace, class, protected override, etc...
    Could someone write a very simple complete program so I can see everything from start to finish?
    Maybe: buy at the mrkt open with a limit order, 3pt target and 2.5 pt Stop.

    #2
    In each and every NinjaTrader installation, there is a sample strategy called "SampleMACrossover". This is a complete strategy and this is the code:
    Code:
    // 
    // Copyright (C) 2006, NinjaTrader LLC <www.ninjatrader.com>.
    // NinjaTrader reserves the right to modify or overwrite this NinjaScript component with each release.
    //
    
    #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")]
            [Category("Parameters")]
            public int Fast
            {
                get { return fast; }
                set { fast = Math.Max(1, value); }
            }
    
            /// <summary>
            /// </summary>
            [Description("Period for slow MA")]
            [Category("Parameters")]
            public int Slow
            {
                get { return slow; }
                set { slow = Math.Max(1, value); }
            }
            #endregion
        }
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks so much Austin. I will study this and put the pieces together and hopefully not have too many errors.

      Comment

      Latest Posts

      Collapse

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