• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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 Bionian, Today, 10:10 AM
      2 responses
      15 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by D Trader, Today, 01:41 PM
      0 responses
      7 views
      0 likes
      Last Post D Trader  
      Started by rexmie888, Today, 04:00 AM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by terminatorT1000, Today, 01:23 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by Tradarr, Today, 12:25 PM
      0 responses
      7 views
      0 likes
      Last Post Tradarr
      by Tradarr
       
      Working...
      X