I am trying to test a simple strategy in Market Replay, that opens 1 stop buy order and 1 stop sell order at the same time (it is not 2 orders in the same direction), but the strategy opens only one of them, never opens both orders as expected.
The code is the following:
#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 ordensimple2 : Strategy
{
#region Variables
// Wizard generated variables
private int sL = 20; // Default setting for SL
private int tP = 20; // Default setting for TP
// 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()
{
SetProfitTarget("", CalculationMode.Ticks, TP);
SetStopLoss("", CalculationMode.Ticks, SL, false);
CalculateOnBarClose = false;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (ToTime(Time[1]) == ToTime(3, 30, 0))
{
EnterShortStop(DefaultQuantity, Low[1] + -5 * TickSize, "StopSell");
EnterLongStop(DefaultQuantity, High[1] + 10 * TickSize, "StopBuy");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int SL
{
get { return sL; }
set { sL = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int TP
{
get { return tP; }
set { tP = Math.Max(1, value); }
}
#endregion
}
}
Please let me know where is wrong handling orders in this strategy.
Thanks in advance,
Federico

Comment