I don't understand why the stop loss is inconsistent, ranging from -200 to -3000.
Below is the script of the wizard created strategy:
========== START ==============
// 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 MyCustomStrategy2 : Strategy
{
#region Variables
// Wizard generated variables
private int barsUp = 5; // Default setting for BarsUp
private int barsDown = 5; // Default setting for BarsDown
private int sL = 20; // Default setting for SL
private int buySellSig = 1; // Default setting for BuySellSig
// 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("NBarsUp", CalculationMode.Ticks, SL, false);
SetStopLoss("NBarsDown", CalculationMode.Ticks, SL, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (NBarsUp(BarsUp, true, false, false)[0] == BuySellSig)
{
EnterLong(DefaultQuantity, "NBarsUp");
ExitShort("NBarsDown", "NBarsDown");
}
// Condition set 2
if (NBarsDown(BarsDown, true, false, false)[0] == BuySellSig)
{
EnterShort(DefaultQuantity, "NBarsDown");
ExitLong("NBarsUp", "NBarsUp");
}
}
#region Properties
[Description("BarsUp")]
[GridCategory("Parameters")]
public int BarsUp
{
get { return barsUp; }
set { barsUp = Math.Max(0, value); }
}
[Description("BarsDown")]
[GridCategory("Parameters")]
public int BarsDown
{
get { return barsDown; }
set { barsDown = Math.Max(0, value); }
}
[Description("Stop loss")]
[GridCategory("Parameters")]
public int SL
{
get { return sL; }
set { sL = Math.Max(0, value); }
}
[Description("If buy / sell signals equal this...")]
[GridCategory("Parameters")]
public int BuySellSig
{
get { return buySellSig; }
set { buySellSig = Math.Max(1, value); }
}
#endregion
}
}
========== END ===========

Comment