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("", "");
}
}
Comment