One of the problems I'm having is trying the sell order back to the buy order. I saw this thread:
Do I need something like this: entryOrder.Token == order.Token
#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>
/// simple strategy to play around for the rest of the day
/// </summary>
[Description("simple strategy to play around for the rest of the day")]
public class JACKCOVER1 : Strategy
{
#region Variables
// Wizard generated variables
private int stopOutTS = -10; // Default setting for stopOut ticksize
private int targetTS = 20; // Default setting for stopOut ticksize
// User defined variables (add any user defined variables below)
private IOrder myEntryOrder = null;
private IOrder myEntryOrder1 = null;
private IOrder myEntryOrderFLAT = null;
private IOrder myEntryOrder3 = null;
private IOrder stopOutOrder = null;
private IOrder targetOrder = null;
private IOrder stopOutOrder2 = null;
private IOrder targetOrder2 = null;
private IOrder scratchOrder = null;
private IOrder ladderOrder = null;
private double initialPrice = 0;
private double initialPrice1 = 0;
private int signal = 0;
private bool jackChange;
private bool jack;
private int orderQuantity = 0;
private int barNumberOfOrder = 0;
#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()
{
Unmanaged = true;
AddRenko("GC 06-14", 2, MarketDataType.Last );
AddRenko("GC 06-14", 5, MarketDataType.Last );
AddRenko("GC 06-14", 8, MarketDataType.Last );
AddRenko("GC 06-14", 1, MarketDataType.Last );
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
CalculateOnBarClose = false;
}
//(this.DM(50).DiPlus[1] - DM(50).DiMinus[1] > 2) && (this.DM(50).DiPlus[5]< DM(50).DiMinus[5]) && this.ADX(14)[5] <15
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if(BarsInProgress == 0)
{
if ( this.Close[0] < this.APZ(1,50).Lower[0] && LinReg(24)[0]> this.APZ(4,200).Lower[0] && Close[2] > Open[2] && Close[3] < Open[3] && myEntryOrder == null &&
//this.KeltnerChannel(this.BarsArray[4],1,10 ).Lower[1] < Close[1] &&
this.DoubleStochastics(this.BarsArray[2], 10)[2] < 10 && this.DoubleStochastics(this.BarsArray[1], 20)[1] > 10 &&
(Closes[3][2] < Opens[3][2] || Closes[3][3] < Opens[3][3] || Closes[3][1] < Opens[3][1] || Closes[3][2] < Opens[3][3]|| Closes[3][3] < Opens[3][2]) && (Closes[2][3] < Opens[2][3]) //&&
//(this.DonchianChannel(BarsArray[2],54).Lower[1] != this.DonchianChannel(BarsArray[2], 7).Lower[1] && this.DonchianChannel(BarsArray[3],24).Lower[1] != this.DonchianChannel(BarsArray[3], 7).Lower[1])
//&& this.APZ( 1, 5).Upper[1] > this.APZ( 2,200).Lower[1]
)
{
myEntryOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Limit, 1, this.GetCurrentBid() - 4 * TickSize, 0 , "", "Reverse-BUY");
barNumberOfOrder = CurrentBar;
initialPrice = myEntryOrder.LimitPrice;
if(ladderOrder != null)
{
CancelOrder(ladderOrder);
ladderOrder = null;
}
}
if (Position.MarketPosition == MarketPosition.Flat && myEntryOrder != null && CurrentBar > barNumberOfOrder + 1)
{
Print("Cancel A Long");
CancelOrder(myEntryOrder);
myEntryOrder = null;
barNumberOfOrder = 0;
}
//////////////////////////////////////////////////////STOP UPDATE LOGIC****************************************************************************************
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///
if(Position.MarketPosition == MarketPosition.Flat)
{
jack = true;
jackChange = true;
}
if (stopOutOrder != null && Position.MarketPosition != MarketPosition.Flat && Closes[4][0] >= this.initialPrice + 3*TickSize && jack == true )
{
ChangeOrder(stopOutOrder, 1, 0, initialPrice);
if(Position.MarketPosition != MarketPosition.Flat && stopOutOrder.StopPrice == initialPrice)
{
jack = false;
this.Print(" HELLO THIS SHOULD TOGGLE");
if(jack==false)
this.Print("false");
}
}
/// //////////////////////////////////////////////////PROFIT UPDATE LOGIC*************************************************************************************************
if (targetOrder != null && Position.MarketPosition != MarketPosition.Flat && Closes[4][0] <= this.initialPrice - 8*TickSize && jackChange == true)
{
ChangeOrder(targetOrder, 1, initialPrice -5 * TickSize , 0);
if(Position.MarketPosition != MarketPosition.Flat && targetOrder.LimitPrice == initialPrice - 5 * TickSize)
{
jackChange = false;
this.Print(" HELLO THIS SHOULD TOGGLE");
if(jackChange==false);
this.Print("false");
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (Position.MarketPosition == MarketPosition.Flat && myEntryOrder != null && this.DonchianChannel(this.BarsArray[4], 54).Upper[0] == Closes[1][0])
{
Print("Cancel B Long");
CancelOrder(myEntryOrder);
myEntryOrder = null;
}
}
}
protected override void OnExecution(IExecution execution)
{
if (execution.Order != null && execution.Order == myEntryOrderFLAT && execution.Order.OrderState == OrderState.Filled)
{
//submit your second order
if(myEntryOrder3 != null)
{
CancelOrder(myEntryOrder3);
Print("Cancel C Long");
myEntryOrder3 = null;
}
}
if (execution.Order != null && execution.Order == myEntryOrder3 && execution.Order.OrderState == OrderState.Filled)
{
//submit your second order
if(myEntryOrderFLAT != null)
{
CancelOrder(myEntryOrderFLAT);
Print("Cancel D Long");
myEntryOrderFLAT = null;
}
}
if (execution.Order != null && execution.Order == targetOrder && execution.Order.OrderState == OrderState.Filled)
{
//submit your second order
if(myEntryOrder1 != null)
{
CancelOrder(myEntryOrder1);
Print("Cancel E Long");
myEntryOrder1 = null;
}
}
if (execution.Order != null && execution.Order == myEntryOrder && execution.Order.OrderState == OrderState.Filled)
{
Print("PLACE ORDERS");
stopOutOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, initialPrice - 15* TickSize, "", "StopOut");
Print("STOPOUTORDERS");
targetOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, initialPrice + 5* TickSize, 0, "", "Profit");
Print("TARGET ORDERS");
Print("Orders Placed");
Print("Orders Confirmed");
}
if (execution.Order != null && execution.Order == stopOutOrder && execution.Order.OrderState == OrderState.Filled)
{
if (targetOrder != null)
{
CancelOrder(targetOrder);
Print("Cancel E Long");
targetOrder = null;
}
}
if (execution.Order != null && execution.Order == targetOrder && execution.Order.OrderState == OrderState.Filled)
{
if(stopOutOrder != null)
{
CancelOrder(stopOutOrder);
Print("Cancel J Long");
stopOutOrder = null;
}
if (scratchOrder != null)
{
CancelOrder(scratchOrder);
Print("Cancel F Long");
scratchOrder = null;
}
if(Position.MarketPosition == MarketPosition.Flat)
Print("Cancel K Long");
TigerCancelOrder();
if (myEntryOrder != null)
{
CancelOrder(myEntryOrder);
Print("Cancel G Long");
myEntryOrder = null;
}
}
if (execution.Order != null && execution.Order == scratchOrder && execution.Order.OrderState == OrderState.Filled)
{
if (targetOrder != null)
{
CancelOrder(targetOrder);
Print("Cancel H Long");
targetOrder = null;
}
}
if (execution.Order != null && execution.Order == ladderOrder && execution.Order.OrderState == OrderState.Filled)
{
if (targetOrder != null)
{
CancelOrder(targetOrder);
Print("Cancel I Long");
targetOrder = null;
}
if(Position.MarketPosition == MarketPosition.Flat)
Print("ladder cancel");
TigerCancelOrder();
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (myEntryOrder != null && myEntryOrder == order)
{
// Rejection handling
if (order.OrderState == OrderState.Rejected)
{
// myEntryOrder was rejected !!!!
// Do something about it here
CancelOrder(myEntryOrder);
Print("Cancel J Long");
myEntryOrder = null;
}
}
}
public void TigerStopOutAndLimit(){
if (myEntryOrder != null && Position.MarketPosition == MarketPosition.Long)
{
Print(this.Orders.Capacity);
stopOutOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, 1, 0, initialPrice - 15* TickSize, "jack2", "StopOut");
Print("STOPOUTORDERS");
targetOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, initialPrice + 10* TickSize, 0, "jack2", "Profit");
Print("TARGET ORDERS");
}
}
public void TigerCancelOrder(){
if (stopOutOrder != null)
{
CancelOrder(stopOutOrder);
Print("Cancel **** Long");
stopOutOrder = null;
}
if (targetOrder != null)
{
CancelOrder(targetOrder);
Print("Cancel ****B Long");
targetOrder = null;
}
}
#region Properties
[Description("")]
[GridCategory("Parameters")]
public int TargetOrderTS
{
get { return targetTS; }
set { targetTS = Math.Max(1, value); }
}
[Description("")]
[GridCategory("Parameters")]
public int StopOrderTS
{
get { return stopOutTS; }
set { stopOutTS = Math.Min(1, value); }
}
#endregion
}
}

Comment