I have the following code in a strategy to be able to place orders above or below the market so that when the price retraces my order is filled and then a sop/profit target is set, However, I am getting no entries whatsoever. Whenever I enable the strategy the control panel shows me as having a position of 2L but my code shows nothing. I have done a DB reset and also used "wait until flat,synchronize account". Below is the onOrderUpdate and onOrderExecution code. I have tried to follow one of your example strategies and this is working but does show no positions when I enable it and neither does another strategy.
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled,
double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
if (order.Name == buySignalName || order.Name == sellSignalName
|| order.Name == buySignalName2 || order.Name == sellSignalName2)
{
entryOrder = order;
// Reset the entryOrder object to null if order was cancelled without any fill
if (order.OrderState == OrderState.Cancelled && order.Filled == 0)
entryOrder = null;
}
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (entryOrder != null && entryOrder == execution.Order)
{
if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
{
if( execution.Order.IsLong)
{
stopOrder1 = ExitLongStopMarket(0, true, execution.Order.Filled, setStopLossPrice, "Stop1", buySignalName);
Draw.HorizontalLine(this, "SL1",setStopLossPrice,Brushes.DarkOrange);
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + ProfitTarget1 * TickSize, "Target", buySignalName);
Draw.HorizontalLine(this, "PT1",execution.Order.AverageFillPrice + ProfitTarget1 * TickSize,Brushes.CornflowerBlue);
}
if( execution.Order.IsShort)
{
//if short should orders be other way around?????
stopOrder1 = ExitLongStopMarket(0, true, execution.Order.Filled, setStopLossPrice, "Stop1", sellSignalName);
Draw.HorizontalLine(this, "SL1",setStopLossPrice,Brushes.DarkOrange);
targetOrder = ExitLongLimit(0, true, execution.Order.Filled, execution.Order.AverageFillPrice + ProfitTarget1 * TickSize, "Target", sellSignalName);
Draw.HorizontalLine(this, "PT1",execution.Order.AverageFillPrice + ProfitTarget1 * TickSize,Brushes.CornflowerBlue);
}
// Resets the entryOrder object to null after the order has been filled
if (execution.Order.OrderState != OrderState.PartFilled)
entryOrder = null;
}
}
protected void SetSellOrder(double entryPrice, string signalName)
{
EnterShortStopMarket(0, true, Quantity, entryPrice , sellSignalName);
currentBarOnEntry = setCancelWorkingOrdersBar();
}
protected void SetBuyOrder(double entryPrice, string signalName)
{
EnterLongStopMarket(0, true, Quantity, entryPrice, buySignalName);
currentBarOnEntry = setCancelWorkingOrdersBar();
}
If anyone can point me in the direction of what I am doing wrong I would be very greatful.
Thanks
Comment