i'm trying to backtest a MACD crossover strategy created with the strategy wizard.
The strategy works but the stop loss doesn't seem to function.
Can anyone help me, I'm using Ninjatrader 7.
This is the generated code from the wizard:
// 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 MACDCrossing : 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()
{
SetStopLoss("CrossoverLong", CalculationMode.Percent, 5, false);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (CrossAbove(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
{
EnterLong(DefaultQuantity, "CrossoverLong");
}
// Condition set 2
if (CrossBelow(MACD(12, 26, 9), MACD(12, 26, 9).Avg, 1))
{
ExitLong("", "");
}
}
ecc.
Comment