Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

working orders

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    working orders

    Hi

    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

    #2
    Hello fishbed,

    Thanks for writing in.

    It sounds like your strategy is entering a position historically and the strategy's logic is preventing any additional entries.

    As a test, you could add a return condition to OnBarUpdate() to prevent any virtual positions to be taken historically when you enable a strategy.

    Code:
    if (State == State.Historical)
        return;
    The different States within NinjaTrader 8 can be referenced here - http://ninjatrader.com/support/helpG...-us/?state.htm

    Please let me know if I may be of further assistance.
    JimNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by yeikson89, Today, 02:53 PM
    2 responses
    10 views
    0 likes
    Last Post yeikson89  
    Started by sdauteuil, Today, 01:06 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by trumpy, 03-09-2017, 02:11 PM
    30 responses
    3,224 views
    0 likes
    Last Post foxthorn  
    Started by shani77, Today, 09:58 AM
    1 response
    23 views
    0 likes
    Last Post NinjaTrader_Eleanore  
    Started by cjanau, Yesterday, 11:07 AM
    1 response
    31 views
    0 likes
    Last Post NinjaTrader_ThomasC  
    Working...
    X