Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

try/catch block for stop loss order error

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

    try/catch block for stop loss order error

    I get the attached error and tried to use the following code to deal with it so my position is not uncovered...does not work...possibly because the atm is placing the stop?

    please advise correct syntax...thanks


    try
    {
    AtmStrategyCreate(Cbi.OrderAction.Sell, .............);
    }
    catch (Exception)
    {
    ....
    }
    Attached Files

    #2
    Hi ATI user,

    This likely has to do with the value for the entry you are using. Ensure it is not above the market for a sell order, or that is does not exist between the spread of the bid and ask.
    TimNinjaTrader Customer Service

    Comment


      #3
      I know what is causing the error...quick market

      my post was how to catch the exception instead of having the stop rejected and therefore an uncovered position

      i.e. how do I "catch" the exception?

      Comment


        #4
        Hi ATI user,


        You cannot "catch" this type of error, the error is a result of the order being rejected by your broker (or simulated).

        You will need to submit a valid Stop order price.

        The other alternative is to disable realtime error handling, and resubmit the Stop, at a valid price.
        More info at - http://www.ninjatrader-support.com/H...eErrorHandling
        TimNinjaTrader Customer Service

        Comment


          #5
          it would appear that
          protected override void Initialize()
          {
          RealtimeErrorHandling = RealtimeErrorHandling.TakeNoAction;
          }
          private IOrder stopLossOrder = null;
          protected override void OnBarUpdate()
          {
          if (entryOrder == null && Close[0] > Open[0])
          EnterLong();

          if (stopLossOrder == null)
          stopLossOrder = ExitLongStop(Position.AvgPrice - 10 * TickSize);
          }
          protected override void OnOrderUpdate(IOrder order)
          {
          if (stopLossOrder != null && stopLossOrder.Token == order.Token)
          {
          // Rejection handling
          if (order.OrderState == OrderState.Rejected)
          {
          // Stop loss order was rejected !!!!
          // Do something about it here
          }
          }
          }

          does not apply to atm originated trades ...right?

          ....edit......................................

          seems to me that:

          if (orderIdLONG.Length > 0)
          {
          string[] status = GetAtmStrategyEntryOrderStatus(orderIdLONG );
          if ( status.GetLength(0) > 0 && status[2] == "Filled"
          )
          {
          }
          if (status[2] == "Rejected")
          ...do something

          should work...but does not pickup the rejection of the "stop1" being placed....just the "entry" portion

          how do I access 'stop1' rejections for atm trades??
          Last edited by ATI user; 06-04-2010, 10:48 AM.

          Comment


            #6
            Hi ATI user,

            The RealtimeErrorHandling will allow you to ignore rejected order, however, you are correct, if you decide to use this feature, you will not be able to monitor order from strategies that call ATM strategies.
            TimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            600 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            347 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            103 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            558 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            558 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X