In my strategy I want open 2 orders in the same time.
myEntryOrderLONG = EnterLongLimit(0, true, noContratti, PgPDn,"EntryLONG");
…
myEntryOrderSHORT = EnterShortLimit(0, true, noContratti, PgPUp, "EntrySHORT");
…
Unfortunately I noticed that just one is opened (see the attachment file).
What is wrong on my program?
Thank you for jour help,
Michele
--------------------------
#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 uuuuu : Strategy
{
#region Variables
// Wizard generated variables
private int myInput0 = 1; // Default setting for MyInput0
private int noContratti = 1;
// Gestione degli ordini
private IOrder myEntryOrderLONG = null; //
private IOrder myExitOrderLONG = null; //
private IOrder myEntryOrderSHORT = null; //
private IOrder myExtitOrderSHORT = null; //
private IOrder myStoploss = null; //
private bool newTrade = true;
// Gestione dei prezzi
private double PgPUp; // Prezzo Ping Pong alto
private double PgPDn; // Prezzo Ping Pong basso
private int range; // altezza range in corso
private int PrecRange; // Altezza range precedente
// Altro
#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 = false;
IncludeCommission = true;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
//Exclure toutes les données historiques
if(Historical)
return;
if(FirstTickOfBar)
{
//Uscita di sicurezza dal trading
if (myExitOrderLONG != null)
{
ExitLong("UscitaBrutaleLONG", "");
}
if (myExtitOrderSHORT != null)
{
ExitShort("UscitaBrutaleSHORT", "");
}
PrecRange = 0;
if ((myEntryOrderLONG == null && myEntryOrderSHORT == null) ||
((myEntryOrderLONG != null && myEntryOrderLONG.LimitPrice < Open[0]) &&
(myEntryOrderSHORT != null && myEntryOrderSHORT.LimitPrice > Open[0])
)
)
{
PgPUp = Open[0] + TickSize * (1 + BarsPeriod.Value);
myEntryOrderLONG = EnterLongLimit(0, true, noContratti, PgPDn,"EntryLONG");
PgPDn = Open[0] - TickSize * (1 + BarsPeriod.Value);
myEntryOrderSHORT = EnterShortLimit(0, true, noContratti, PgPUp, "EntrySHORT");
newTrade = true;
}
else
newTrade = false;
}
range = Convert.ToInt16((High[0] - Low[0]) / TickSize);
if (PrecRange < range && newTrade)
{
PgPUp = Low[0] + TickSize * (1 + BarsPeriod.Value);
if(myEntryOrderSHORT != null && myEntryOrderSHORT.LimitPrice != PgPUp)
myEntryOrderSHORT = EnterShortLimit(0, true, noContratti, PgPUp, "EntrySHORT");
PgPDn = High[0] - TickSize * (1 + BarsPeriod.Value);
if(myEntryOrderLONG != null && myEntryOrderLONG.LimitPrice != PgPDn)
myEntryOrderLONG = EnterLongLimit(0, true, noContratti, PgPDn,"EntryLONG");
PrecRange = range;
}
}
/// <summary> ----------------------------------------------------------------------------------------
/// Questo medoto è attivo ogni qualvolta avviene un cambiamento di stato nell'ordine
/// </summary> ---------------------------------------------------------------------------------------
protected override void OnOrderUpdate(IOrder order)
{
double valexit;
if (myEntryOrderLONG != null && myEntryOrderLONG == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
myEntryOrderLONG = null;
}
}
if (myEntryOrderSHORT != null && myEntryOrderSHORT == order)
{
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
{
myEntryOrderSHORT = null;
}
}
}
/// <summary> ----------------------------------------------------------------------------------------
/// Called on each incoming execution
/// </summary> ----------------------------------------------------------------------------------------
protected override void OnExecution(IExecution execution)
{
double valexit;
// ----------- LONG ----------------
if (myEntryOrderLONG != null && myEntryOrderLONG == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
myStoploss = ExitLongStop(execution.Order.LimitPrice - 2*TickSize, "StopLossLONG", "EntryLONG");
myExitOrderLONG = ExitLongLimit(execution.Order.LimitPrice + TickSize,
"EsciLONG", "EntryLONG");
if (myEntryOrderSHORT != null)
CancelOrder(myEntryOrderSHORT);
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
myEntryOrderLONG = null;
}
}
}
// ------------ SHORT ---------------
if (myEntryOrderSHORT != null && myEntryOrderSHORT == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
myStoploss = ExitShortStop(execution.Order.LimitPrice + 2*TickSize , "StopLossSHORT", "EntrySHORT");
myExtitOrderSHORT = ExitShortLimit(execution.Order.LimitPrice - TickSize,
"EsciSHORT", "EntrySHORT");
if (myEntryOrderLONG != null)
CancelOrder(myEntryOrderLONG);
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
{
myEntryOrderSHORT = null;
}
}
}
// Reset our stop order and target orders' IOrder objects after our position is closed.
if ((myStoploss != null && myStoploss == execution.Order) || (myExtitOrderSHORT != null && myExtitOrderSHORT == execution.Order)
|| (myExitOrderLONG != null && myExitOrderLONG == execution.Order))
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled)
{
myStoploss = null;
myExtitOrderSHORT = null;
myExitOrderLONG = null;
}
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int MyInput0
{
get { return myInput0; }
set { myInput0 = Math.Max(1, value); }
}
[Description("N° di contratti per operazione")]
[GridCategory("Parameters")]
public int NoContratti
{
get { return noContratti; }
set { noContratti = value; }
}
#endregion
}
}

Comment