I have a simple test strategy which defines three limit levels with a profit target for each level. To my understanding the maxumum number of contracts this strategy should buy at once is 6 (1+2+3), but somehow nine contracts get bought. In this particular case that happens after the limit L3 gets executed twice at 14:01:09 and 14:05:06.
The settings for the Order Handling are:
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
What am I doing wrong?
Thank you in advance.
Vassil
#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 TestLimit : Strategy
{
#region Variables
// Wizard generated variables
private double distance = 2.0; // Default setting for Distance
private double profit = 1.0; // Default setting for Profit
private int timeBegin = 1000; // 10:00:00
// User defined variables (add any user defined variables below)
private double level1, level2, level3;
#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;
BarsRequired = 2;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.UniqueEntries;
ExitOnClose = true;
ExitOnCloseSeconds = 120;
TraceOrders = true;
ClearOutputWindow(); // just for easier debugging
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (ToDay(Time[0]) != ToDay(Time[1]))
{
level1 = level2 = level3 = 0;
}
if (Math.Floor(ToTime(Time[0]) / 100.0) == timeBegin)
{
level1 = Close[0] - 1 * distance;
level2 = Close[0] - 2 * distance;
level3 = Close[0] - 3 * distance;
Print(Time[0] + " level1=" + level1 + " level2=" + level2 + " level3=" + level3);
}
if (level1 > 0 && level2 > 0 && level3 > 0)
{
EnterLongLimit(1, level1, "L1");
EnterLongLimit(2, level2, "L2");
EnterLongLimit(3, level3, "L3");
ExitLongLimit(1, level1 + profit, "lx1", "L1");
ExitLongLimit(2, level2 + profit, "lx2", "L2");
ExitLongLimit(3, level3 + profit, "lx3", "L3");
}
}
#region Properties
[Description("")]
[Category("Parameters")]
public double Distance
{
get { return distance; }
set { distance = value; }
}
[Description("")]
[Category("Parameters")]
public double Profit
{
get { return profit; }
set { profit = value; }
}
[Description("")]
[Category("Parameters")]
public int TimeBegin
{
get { return timeBegin; }
set { timeBegin = value; }
}
#endregion
}
}

Comment