I am having problems with my strategy I will post the code in a minute . The idea of the system is it goes long and short with limit orders and has profit targets as well . The issue I am having is where as an example i am short from a signal and the profit target is not hit but a long signal is generated in the opposite direction say 3 bars later , my system is not taking the long position . In fact whenever a profit target is not met and a signal occurs in the opposite direction the system does not take the signal , I thought NT logic was supposed to handle the closing of positions first and then open the others , here is the code :
/// <summary>
/// Simple Long Short Test
/// </summary>
[Description("Simple Long Short Test")]
public class New : Strategy
{
#region Variables
// Wizard generated variables
private int target = 3; // Default setting for Target
// 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, Target);
CalculateOnBarClose = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
// Condition set 1
if (Close[0] > High[2]
&& Close[1] <= High[2]
&& Close[1] < High[3])
{
EnterLongLimit(DefaultQuantity, Close[0] + 1 * TickSize, "");
}
// Condition set 2
if (Close[0] > High[2]
&& Close[1] <= High[3]
&& Close[0] >= High[3])
{
EnterLongLimit(DefaultQuantity, Close[0] + 1 * TickSize, "");
}
// Condition set 3
if (Close[0] < Low[2]
&& Close[1] >= Low[2]
&& Close[1] > Low[3])
{
EnterShortLimit(DefaultQuantity, Close[0] + -1 * TickSize, "");
}
// Condition set 4
if (Close[0] < Low[2]
&& Close[1] >= Low[3]
&& Close[0] <= Low[3])
{
EnterShortLimit(DefaultQuantity, Close[0] + -1 * TickSize, "");
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int Target
{
get { return target; }
set { target = Math.Max(1, value); }
}
#endregion
}
}
Comment