Post
Topic
Board Speculation
Re: Goomboo's Journal
by
Partinez
on 21/04/2014, 11:52:38 UTC
Hi Goomboo, I've just discovered your post and really appreciate that you share your knowledge. I've downloaded Ninjatrader to backtest the strategy and test some other ones, but I'm not getting the expected results. Maybe you or anyone can let me see where I'm wrong.

First of all, I'm having problems getting the required format to import the data, but I found some historical data here that I am using.

Next, I created a new strategy, using the EMA 10/21 strategy. I am pasting the strategy script, maybe the mistake is there.
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
{
    ///
    /// Enter the description of your strategy here
    ///

    [Description("Enter the description of your strategy here")]
    public class EMAcrossover2 : Strategy
    {
        #region Variables
        // Wizard generated variables
        private int short_EMA = 10; // Default setting for Short_EMA
        private int long_EMA = 21; // Default setting for Long_EMA
        // User defined variables (add any user defined variables below)
        #endregion

        ///
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        ///

        protected override void Initialize()
        {

            CalculateOnBarClose = true;
        }

        ///
        /// Called on each bar update event (incoming tick)
        ///

        protected override void OnBarUpdate()
        {
            // Condition set 1
            if (EMA(Short_EMA)[0] > EMA(Long_EMA)[0]
                && EMA(Short_EMA)[1] < EMA(Long_EMA)[1])
            {
                EnterLong(DefaultQuantity, "");
                ExitShort("", "");
            }

            // Condition set 2
            if (EMA(Long_EMA)[0] > EMA(Short_EMA)[0]
                && EMA(Long_EMA)[1] < EMA(Short_EMA)[1])
            {
                EnterShort(DefaultQuantity, "");
                ExitLong("", "");
            }
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public int Short_EMA
        {
            get { return short_EMA; }
            set { short_EMA = Math.Max(1, value); }
        }

        [Description("")]
        [GridCategory("Parameters")]
        public int Long_EMA
        {
            get { return long_EMA; }
            set { long_EMA = Math.Max(2, value); }
        }
        #endregion
    }
}

#region Wizard settings, neither change nor remove
/**/ I've omitted this since it's very long, bit I can post it if needed.
#endregion

I've backtested using the following settings:
http://s30.postimg.org/6gd8pecv5/settings2.jpg

And got the following (scary) results:
http://s29.postimg.org/wkdk1l50n/result_chart.jpg

http://s29.postimg.org/58ib0909z/result_table.jpg

So, where is the problem?