Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Order Entry on Moving Average System

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

    Order Entry on Moving Average System

    I'm trying to create a basic 10 month long only moving average system to backtest. When I test the system on QQQQ, I find that I have order entries just 3 months into QQQQ's existence, before a 10 month average could even be generated. What do I need to correct? And where is NT getting the signal to buy?

    Also, a secondary question: If I want to backtest the same sytem back to January 1st, 1995, I assume NT can 'look back' prior to January 1st 1995 to determin the 10 month SMA when I run a backtest? The reason why I ask is because when I chart SPY with the 10 month moving average indicator, the indicator never starts at the beginning of the chart but is usually several bars in.

    the script is below, the first is a crossover system, the 2nd I wrote if the security closes above the moving average, neither one seems to correct the issue despite having slightly different opening signal price:

    // 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 SMA10MONTH : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #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()
    {
    // Condition set 1
    if (CrossAbove(Close, SMA(10), 1))
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (CrossBelow(Close, SMA(10), 1))
    {
    ExitLong("", "");
    }
    }
    ================================================== ==

    // 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 SMA10MONTH2 : Strategy
    {
    #region Variables
    // Wizard generated variables
    private int myInput0 = 1; // Default setting for MyInput0
    // User defined variables (add any user defined variables below)
    #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()
    {
    // Condition set 1
    if (Close[0] >= SMA(10)[0])
    {
    EnterLong(DefaultQuantity, "");
    }

    // Condition set 2
    if (Close[0] < SMA(10)[0])
    {
    ExitLong("", "");
    }
    }
    Last edited by oyz79; 09-08-2009, 09:50 PM.

    #2
    oyz79, all indicators are calculated from bar 1 on in NinjaTrader, you can't see the first 20 bars when showing the 'unstable period' is turned off as per default in the chart properties - http://www.ninjatrader-support.com/H...roperties.html

    You can add a check to your code triggering the trade execution only after a certain amount of bars (CurrentBar) is processed - http://www.ninjatrader-support.com/H...urrentBar.html
    BertrandNinjaTrader Customer Service

    Comment


      #3
      always check the LOG tab for information when things don't seem to be working.
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        Do you have the moving average test complete? Can I have a copy of the script. I want to get start to learn how to do back test. Thank you

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by ursavent, Today, 12:54 PM
        0 responses
        2 views
        0 likes
        Last Post ursavent  
        Started by Mizzouman1, Today, 07:35 AM
        3 responses
        17 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by RubenCazorla, Today, 09:07 AM
        2 responses
        13 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by i019945nj, 12-14-2023, 06:41 AM
        7 responses
        82 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by timmbbo, 07-05-2023, 10:21 PM
        4 responses
        158 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X