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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X