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

error placing sl

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

    error placing sl

    I have a closed candlestick strategy, in which sometimes the sl must move very close to the price.
    The problem is that in a long trade, for example, the sl must move one tick below the price, but sometimes the price is already two ticks below the price of the sl.
    there is a way to detect when this error occurs, so that the strategy closes the operation with a market order, that is, if it fails to move the sl, it closes the operation, since it is understood that in normal circumstances the sl would have closed it.
    and of course everything without resorting to adding a series of tick data
    would it be correct to use this?
    protected override void OnMarketData(MarketDataEventArgs e){}
    Last edited by franatas; 07-19-2023, 03:50 AM.

    #2
    Hello franatas,

    Thank you for your post.

    You have to be careful when working with a stop loss order very close to the market, especially only one tick below the price. When trading on a live account, if you submit a stop loss order or submit a change in price to an existing stop loss order and by the time it is received by the broker the price has already moved to the other side of the stop loss, this can result in an error/rejection that the stop price can't be on that side of the market.

    OnMarketData() is not the appropriate approach here. The strategy's RealtimeErrorHandling property will determine the strategy's behavior if an error or rejection occurs. The default behavior is RealtimeErrorHandling.StopCancelClose which will stop the strategy, cancel any remaining working orders, and submit a close order to attempt to close any open strategy positions. You could consider using IgnoreAllErrors or StopCancelCloseIgnoreRejects instead of StopCancelClose instead; then you can catch errors/rejections and program your own logic for what your strategy should do in that case. For more details on RealtimeErrorHandling:


    The example on that page shows a way to catch if an order called myStopLoss is rejected, then has a comment "// Do something about it here" where you could add in logic to place another protective order, for example.

    Please let us know if we may be of further assistance.
    Emily C.NinjaTrader Customer Service

    Comment


      #3
      ok gracias, eso es lo que necesito entonces

      Comment


        #4
        In the case of the sl I realized that the rejected sl does not disappear but remains at its previous price when the broker rejects it, at least I never took it off but the notice came out and the sl stayed in place. can you confirm this or it might go away.
        I have put a closure of operations for security but I did not have the opportunity to try. but if I am interested in knowing the previous question

        Comment


          #5
          Hello franatas,

          Thank you for your reply.

          I am not able to confirm if the stop loss from your strategy stayed in place when the reject happened or not. I suggest testing your strategy with TraceOrders enabled in State.SetDefaults to get output whenever an order is submitted, ignored, changed, or canceled:


          You may also add additional print statements to understand your order and what state it is in both before and after the rejection. Typically, once an order is cancelled, filled, rejected, or unknown, that means the order is in a terminal state and no longer active. For more information, please see IsTerminalState() in the help guide here:


          For a general guide on using Print() statements to debug your scripts:


          Please let us know if we may be of further assistance.
          Emily C.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Haiasi, 04-25-2024, 06:53 PM
          2 responses
          16 views
          0 likes
          Last Post Massinisa  
          Started by Creamers, Today, 05:32 AM
          0 responses
          5 views
          0 likes
          Last Post Creamers  
          Started by Segwin, 05-07-2018, 02:15 PM
          12 responses
          1,786 views
          0 likes
          Last Post Leafcutter  
          Started by poplagelu, Today, 05:00 AM
          0 responses
          3 views
          0 likes
          Last Post poplagelu  
          Started by fx.practic, 10-15-2013, 12:53 AM
          5 responses
          5,407 views
          0 likes
          Last Post Bidder
          by Bidder
           
          Working...
          X