Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop not working

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

    Stop not working

    I need a bit of help. Haven't work on strategies for a while and can't make this code work ?

    Code:
    protected override void OnExecution(IExecution execution)
            {
    			//We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
    			//which ensures your strategy has received the execution which is used for internal signal tracking.
    			
    			// Stop-Loss order 3 ATR below our entry price
    			// Resets the entryOrder object to null after the order has been filled or partially filled
    			
    			if (_entryBOrder != null)
    			{
    				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    				{			
    					_stopSOrder = ExitLongStop(1, execution.Order.AvgFillPrice - ((3*atr_indicator[0])));
    //					_targetBOrder = ExitLongLimit(1, execution.Order.AvgFillPrice + (target * TickSize));
    					
    					if (execution.Order.OrderState != OrderState.PartFilled)
    					{
    						_entryBOrder	= null;
    					}
    				}
    			}
    			
    			
    			
    			//We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate()
    			//which ensures your strategy has received the execution which is used for internal signal tracking.
    			
    			// Stop-Loss order 3 ATR above our entry price
    			// Resets the entryOrder object to null after the order has been filled or partially filled
    			
    			if (_entrySOrder != null)
    			{
    				if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0))
    				{
    					_stopBOrder = ExitShortStop(1, execution.Order.AvgFillPrice + (3*atr_indicator[0]));
    						
    //					targetSOrder = ExitShortLimit(1, execution.Order.AvgFillPrice - (target * TickSize));
    					
    					if (execution.Order.OrderState != OrderState.PartFilled)
    					{
    						_entrySOrder	= null;
    					}
    				}
    			}
    			
    		}
    This code is executed once I get filled on my initial entries.
    My entries are working fine but my stop loss are not....


    Thanks

    #2
    Hi blar58,

    Thanks for the post. Have you checked TraceOrders output for any messages related to submission of these orders? Any other working exit orders set so these would be ignored?

    You may also want to review this sample on submitting these types of orders:
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    Main thing is missing the check that verifies your entry order is the order raising the execution event.

    if (_entryBOrder != null && _entryBOrder == execution.order)
    Last edited by NinjaTrader_RyanM1; 09-06-2011, 02:46 PM.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Ryan

      Where do I have to do this check ? In the OnExecution method ?
      If so I would have to use execution.Order

      Also in my Trace Order I have a few Ignore ( Reason This was an exit order but no position exists to exit ) and Canceled "expired" Order

      In the Trace Order it seems that it cancels the order "Cancelled expired order !
      Last edited by blar58; 09-06-2011, 02:39 PM.

      Comment


        #4
        Yes, you're right. In OnExecution, that would be done with execution.Order.

        From the trace orders output, it sounds like you're submitting those orders during other fills, so adding that check may help clean it up and only submit once the entry order fills.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Ryan

          I did clen up my code but the problem persists. My stop orders are not executed

          Comment


            #6
            Ryan

            I am using BarsInProgress in my code because I have two data series daily and 5 minutes.

            The orders are triggered only on the 5 minutes and the OnExecution method is executed on the 5 minutes timeframe only so I do not need to refer these orders to BarsInProgress.

            Am I right ?

            I have also noticed that the stop get triggered if it happens ON THE SAME BAR. If not on the same bar they get canceled !
            Last edited by blar58; 09-06-2011, 03:53 PM.

            Comment


              #7
              BarsInProgress shouldn't affect your order submission here, as you're monitoring for executions, not bar updates. The execution event is raised when the entry order is filled and this is what you're using for your protective order submission.

              I have also noticed that the stop get triggered if it happens ON THE SAME BAR. If not on the same bar they get canceled !
              This may explain what you're seeing. Your orders are submitted, but if they are not filled on the bar they're submitted to, then they're cancelled. In order to submit liveUntilCancelled orders, you must use this advanced overload, available for all non-market orders.

              ExitLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName, string fromEntrySignal)

              If you need to manually cancel this order for any reason, this reference sample can help:
              When using NinjaTrader's Enter() and Exit() methods, the default behavior is to automatically expire them at the end of a bar unless they are resubmitted to keep them alive. Sometimes you may want more flexibility in this behavior and wish to submit orders as live-until-cancelled. When orders are submitted as live-until
              Ryan M.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

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