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

Orders getting cancelled with no reason

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

    Orders getting cancelled with no reason

    Hello, i got this..
    Code:
    protected override void OnOrderUpdate(Cbi.Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, Cbi.OrderState orderState, DateTime time, Cbi.ErrorCode error, string comment) {
                Print(order.Name + ": " + orderState.ToString());
                if (error != ErrorCode.NoError) {
                    Print("Error: " + error.ToString());
                }
            }
    
            protected override void OnPositionUpdate(Cbi.Position position, double averagePrice, int quantity, Cbi.MarketPosition marketPosition) {
                if (done) {
                    return;
                }
    
                if (position.MarketPosition == MarketPosition.Long) {
                    done = true;
                    EnterShortLimit(averagePrice + (TickSize * 3), "sl1");
                    //EnterShortStopMarket(averagePrice - (TickSize * 5), "ssm1");
                } else {
    
                }
            }
    
            protected override void OnBarUpdate() {
    
                if (BarsInProgress != 0) {
                    return;
                }
    
                if (CurrentBar < BarsRequiredToTrade) {
                    return;
                }
    
                if (Position.MarketPosition == MarketPosition.Flat) {
                    if (!done) {
                        EnterLongLimit(GetCurrentBid(), "ll0");
                    }
                }
    
            }
    And i get this at the Output window..
    ll0: Submitted
    ll0: Accepted
    ll0: Working
    ll0: Filled
    Close position: Submitted
    Close position: Accepted
    Close position: Working
    sl1: Submitted
    sl1: Accepted
    sl1: Working
    Close position: CancelPending
    Close position: CancelSubmitted
    Close position: Cancelled
    sl1: CancelPending
    sl1: CancelSubmitted
    sl1: Cancelled
    The "sl1" order is supposed to work as a "take profit" right? Well, it's being cancelled..

    And other question, i have the "ssm1" order commented because it doesn't work together with "sl1", why is that?
    The idea is to avoid the "SetProfit.." and "StopLoss.." methods.
    Last edited by Fernand0; 12-16-2019, 10:11 PM.

    #2
    Hi Fernand0, thanks for your post.

    The order is being cancelled because you need to re-submit the order on every bar to keep it alive. The EnterLongLimit method has an overload that takes an isLiveUntilCancelled bool:

    EnterLongLimit(int barsInProgressIndex, bool isLiveUntilCancelled, int quantity, double limitPrice, string signalName)

    Use this method to keep the order alive automatically.

    Please let me know if I can assist any further.
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks ChrisL!
      Last edited by Fernand0; 12-17-2019, 01:51 PM. Reason: I found examples to do what i wanted.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by ftsc2022, 10-25-2022, 12:03 PM
      5 responses
      255 views
      0 likes
      Last Post KeyonMatthews  
      Started by ScottW, Today, 06:09 PM
      0 responses
      3 views
      0 likes
      Last Post ScottW
      by ScottW
       
      Started by Board game geek, 10-29-2023, 12:00 PM
      14 responses
      244 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Waxavi, 04-19-2024, 02:10 AM
      4 responses
      56 views
      0 likes
      Last Post sonia0101  
      Started by cmtjoancolmenero, Today, 03:58 PM
      0 responses
      9 views
      0 likes
      Last Post cmtjoancolmenero  
      Working...
      X