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

Buy stop and quick market movement

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

    Buy stop and quick market movement

    Hello, what would be the best practice in the case a strategy moves the buy stop loss order to a specific price (SetStopLoss(CalculationMode.Price, ...)), which can be below the market (e.g. because of the delay between the exchange and my machine). In case the order is rejected, is it possible to submit automatically a Market order, or is it necessary to handle the rejection by the strategy code? Or is there a setting or an order type available, which would automatically execute in case the buy stop order is below the market price?

    Or, alternatively would SetStopLoss(CalculationMode.Ticks, -1) work to either lock 1 tick profit, or exit at a market price if the price is below the stop order? Please suggest the best solution. Thank you.

    #2
    Hello mantak007,

    Thank you for your note.

    I put together a sample strategy which when applied to a 5 second chart will submit an EnterLong call, upon which being filled will submit a profit target and stop loss. The stop loss is intentionally submitted above the market so that it’s rejected. In OnOrderUpdate we check if there is an error and that error is OrderRejected, and the order is “Stop Loss”, if so, ExitLong.

    The strategies RealtimeErrorHandling is set to RealtimeErrorHandling.StopCancelCloseIgnoreRejects ;

    See the following sections of our helpguide,


    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you, this is a working solution of course, only there is an extra roundtrip between the exchange and the trading machine to handle the order rejection. I understand it that there is no native solution which would cover this stop-or-market situation.

      Comment


        #4
        Hello mantak007,

        You could check the OrderState instead.

        For example,

        if(Orderstate == OrderState.Rejected)
        <Do Something>

        See the Order Section of our Helpguide,


        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thank you, that's fine, I'll check what works best for my case. May I ask about one technical detail - which party is rejecting a buy stop below the market price, is it Ninjatrader, the broker, or the exchange? If that depends on the broker or instruments, let's say CL futures via Interactive brokers. Do you have this information? My point is, if Ninja is checking and rejecting, the delay is marginal. If it's the exchange, there may be a significant delay causing a slippage. I know we are talking about milliseconds in any case, but I'd like to understand what's really happening.

          Comment


            #6
            Hello Alan,
            I implemented the sample in my strategy, however I'm still getting a message box "Stop price cannot be changed above the market, affected order Sell Stop Market...." . Also, I'm getting lots of such message boxes so Ninjatrader is effectively frozen. The strategy runs on sim101 with Continuum demo data connection. RealtimeErrorHandling is set to IgnoreAllErrors. Is this a known bug, or is there a setting to prevent displaying such alerts?

            Just to give the idea, after 2 hours the strategy has been runing, I have over 3000 open message boxes, 50% CPU usage, I need to kill the process to be able to do anything. Any help appreciated.
            Last edited by mantak007; 04-06-2018, 08:55 AM.

            Comment


              #7
              Hello mantak007,

              Thank you for your response.

              Rejections are reported to NinjaTrader by the brokerage connection. The brokerage technology may have it's own rejection handling or it is reporting from the exchange the rejection. You would need to contact the brokerage directly on such detail.

              The SetStopLoss() has it's own internal handling that is reporting the message you see, this is not technically an order rejection. You would instead need to implement check for this behavior in your code or switch to the use of the Exit methods (such as ExitLongStopMarket) in order to control the Stop Losses and Profit Targets.

              Please let me know if you have any questions.

              Comment


                #8
                Patrick, my issue is that the strategy is showing thousands of message boxes. This is a critical problem, and my question is, how can I get rid of them. Because anything I do on the client is delayed and there still can be situations that an order is rejected on the exchange, even though all seemed valid on the client, so in reality I can get such message box no matter what I do. I'm OK with handling the exits even with a delay, what I'm not OK with are message boxes flooding the trading machine out of control. Any suggestion except not using SetStopLoss?

                Comment


                  #9
                  Hello mantak007,

                  Thank you for your response.

                  To be clear I am not suggesting not to use SetStopLoss() as any incorrectly placed order can cause the message to appear. There is no means to prevent the message boxes from appearing other than adjusting logic to prevent the scenarios that trigger the message boxes. While you can set your strategy to ignore the message and not disable that does not mean the message boxes are not displayed.

                  Please let me know if you have any questions.

                  Comment


                    #10
                    Hello Patrick, can you please submit a feature request to introduce a silent mode, without such message boxes? It's nice that Ninjatrader can in theory act as an independent algo trading platform, but in reality such issues limit the usage to academic and test purposes only. It would be great if Ninjatrader could be used also as a full algo platform, without having to monitor it and manually close the message boxes. Thank you.

                    Comment


                      #11
                      Hello mantak007,

                      Thank you for your suggestion, I will submit a feature request for this.

                      Ninjatrader is a full algo platform, writing you strategy in an Addon would give you full control.

                      Thank you for writing in.
                      Alan P.NinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by mantak007 View Post
                        Hello, what would be the best practice in the case a strategy moves the buy stop loss order to a specific price (SetStopLoss(CalculationMode.Price, ...)), which can be below the market (e.g. because of the delay between the exchange and my machine). In case the order is rejected, is it possible to submit automatically a Market order, or is it necessary to handle the rejection by the strategy code? Or is there a setting or an order type available, which would automatically execute in case the buy stop order is below the market price?

                        Or, alternatively would SetStopLoss(CalculationMode.Ticks, -1) work to either lock 1 tick profit, or exit at a market price if the price is below the stop order? Please suggest the best solution. Thank you.
                        That is an excellent question. How much do you think the delay between the machine and the market order be? Will it affect it by that great a number?

                        Comment


                          #13
                          Originally posted by mantak007 View Post
                          Hello Patrick, can you please submit a feature request to introduce a silent mode, without such message boxes? It's nice that Ninjatrader can in theory act as an independent algo trading platform, but in reality such issues limit the usage to academic and test purposes only. It would be great if Ninjatrader could be used also as a full algo platform, without having to monitor it and manually close the message boxes. Thank you.
                          This is accurate. A full algo platform will be nice to work on.

                          Comment


                            #14
                            Hello ethan278,

                            The feature request tracking the ability to disable order warning pop ups is being tracked under, SFT-671. If you'd like to add your vote you can comment on this thread or send an email to platform support at NinjaTrader dot com requesting your vote be added.

                            How long would depend on your connection as well as your brokers connection to the exchange.

                            Within your trace file you could look at the difference between OrderState.Submitted and either OrderState.Accepted or OrderState.Working for an idea of how long this time takes.

                            Please let us know if you need further assistance.
                            Alan P.NinjaTrader Customer Service

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by love2code2trade, Yesterday, 01:45 PM
                            3 responses
                            22 views
                            0 likes
                            Last Post NinjaTrader_BrandonH  
                            Started by trilliantrader, Today, 08:16 AM
                            2 responses
                            6 views
                            0 likes
                            Last Post trilliantrader  
                            Started by samish18, Today, 08:31 AM
                            1 response
                            1 view
                            0 likes
                            Last Post NinjaTrader_Clayton  
                            Started by Creamers, 09-08-2023, 10:26 AM
                            6 responses
                            157 views
                            0 likes
                            Last Post JonyGurt  
                            Started by funk10101, Today, 08:14 AM
                            1 response
                            2 views
                            0 likes
                            Last Post NinjaTrader_Jesse  
                            Working...
                            X