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.
#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 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
/// <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 (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:
And got the following (scary) results:
So, where is the problem?