Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 GussJ, 03-04-2020, 03:11 PM
    11 responses
    3,228 views
    0 likes
    Last Post xiinteractive  
    Started by andrewtrades, Today, 04:57 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by chbruno, Today, 04:10 PM
    0 responses
    7 views
    0 likes
    Last Post chbruno
    by chbruno
     
    Started by josh18955, 03-25-2023, 11:16 AM
    6 responses
    440 views
    0 likes
    Last Post Delerium  
    Started by FAQtrader, Today, 03:35 PM
    0 responses
    12 views
    0 likes
    Last Post FAQtrader  
    Working...
    X