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 CarlTrading, 05-11-2026, 05:56 AM
            0 responses
            27 views
            0 likes
            Last Post CarlTrading  
            Started by CarlTrading, 05-10-2026, 08:12 PM
            0 responses
            20 views
            0 likes
            Last Post CarlTrading  
            Started by Hwop38, 05-04-2026, 07:02 PM
            0 responses
            183 views
            0 likes
            Last Post Hwop38
            by Hwop38
             
            Started by CaptainJack, 04-24-2026, 11:07 PM
            0 responses
            335 views
            0 likes
            Last Post CaptainJack  
            Started by Mindset, 04-21-2026, 06:46 AM
            0 responses
            260 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Working...
            X