Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error - Order on wrong side of market

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

    Error - Order on wrong side of market

    My strategy enters trades in the following way, enter at market using EnterLong()/EnterShort(), place my stop/targets 10 ticks above/below the entry using SetStopLoss()/SetProfitTarget(), and does a custom trail by calling SetStopLoss() again.

    Most of the time this strategy works fine, but once in a while the orders will get rejected and the strategy will terminate itself saying that one of my orders is on the wrong side of the market. Here is the data for one of these errors. The should have entered at market at 83.54, stop/target +/- 10 ticks. It got filled at 83.48 and the stop should have been at 83.38, target at 83.58, trail 12 ticks

    Error:
    "Sell stop or sell Stop limit orders can't be placed above the market. affected order: Sell 1 Stop @ 83.53"

    Output Window:
    ########## New Trade (08Aug11 12:21:13) ##########
    --- Started BuyMarketReverse
    CL 09-11.122113 - BuyMarketReverse 1 @ 83.54 ---
    >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse
    CL 09-11.122113' State=PendingSubmit Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse
    CL 09-11.122113' State=Accepted Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse
    CL 09-11.122113' State=Working Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='1109fd872ae34055880bbe6aefeeef3b/Sim101' Name='BuyMarketReverse
    CL 09-11.122113' State=Filled Instrument='CL 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=83.48 Token='1109fd872ae34055880bbe6aefeeef3b' Gtd='1/1/0001 12:00:00 AM' <<<
    Order Filled at: 83.48
    >>> OrdeExecution: Execution='c6e90dae4c404858b8b527c224c4d254' Instrument='CL 09-11' Account='Sim101' Name='BuyMarketReverse
    CL 09-11.122113' Exchange=Default Price=83.48 Quantity=1 Market position=Long Commission=0 Order='1109fd872ae34055880bbe6aefeeef3b' Time='8/8/2011 12:21:13 PM' <<<
    >>> PositionUpdate <<<
    ### Standard Position Opened @ 83.4800
    **NT** Strategy 'A0_TradeManager/f35c6b9b33db4301979131b11304ad4e' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
    8/8/2011 12:21:13 PM CancelAllOrders: BarsInProgress=0
    >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=PendingSubmit Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<<
    @@@ Long Trail to 83.36 < 83.48
    8/8/2011 12:21:13 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Price Value=83.36 Currency=0 Simulated=False
    8/8/2011 12:21:14 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False
    8/8/2011 12:21:14 PM Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=10 Currency=0 Simulated=False
    >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Accepted Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Working Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=PendingCancel Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='06617919bf8740fd980194ccb86ebe58/Sim101' Name='Profit target' State=Cancelled Instrument='CL 09-11' Action=Sell Limit price=83.58 Stop price=0 Quantity=1 Type=Limit Tif=Gtc OverFill=False Oco='c6e90dae4c404858b8b527c224c4d254-827' Filled=0 Fill price=0 Token='06617919bf8740fd980194ccb86ebe58' Gtd='1/1/0001 12:00:00 AM' <<<
    8/8/2011 12:21:14 PM Entered internal PlaceOrder() method at 8/8/2011 12:21:14 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Close' FromEntrySignal=''
    >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=PendingSubmit Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Accepted Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Working Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeUpdate: Order='bad669435d544624b562dfcc442b7392/Sim101' Name='Close' State=Filled Instrument='CL 09-11' Action=Sell Limit price=0 Stop price=0 Quantity=1 Type=Market Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=83.44 Token='bad669435d544624b562dfcc442b7392' Gtd='1/1/0001 12:00:00 AM' <<<
    >>> OrdeExecution: Execution='d19230a13f934a6a9b8cc07d981865dc' Instrument='CL 09-11' Account='Sim101' Name='Close' Exchange=Default Price=83.44 Quantity=1 Market position=Short Commission=0 Order='bad669435d544624b562dfcc442b7392' Time='8/8/2011 12:21:15 PM' <<<
    >>> PositionUpdate <<<
    ### Non-ATM Position Closed
    (ATM_MGR) -- CL Reset --
    Non-ATM Position Closed
    8/8/2011 12:21:15 PM Disable() called: strategy disabled
    8/8/2011 12:21:15 PM CancelAllOrders: BarsInProgress=0
    **NT** Disabling NinjaScript strategy 'A0_TradeManager/f35c6b9b33db4301979131b11304ad4e'

    #2
    Hi Monpere,

    This is a coding issue. You have to control submission of orders so they're placed on the right side of market. Set statements will use the last value set in code. If using SetStopLoss() and mode price, it submits exactly at the price specified.

    If you're seeing this after a reversal, consider setting the stop loss to mode ticks in the same block as reversal, but prior to submission of the reversal order.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hi Monpere,

      This is a coding issue. You have to control submission of orders so they're placed on the right side of market. Set statements will use the last value set in code. If using SetStopLoss() and mode price, it submits exactly at the price specified.

      If you're seeing this after a reversal, consider setting the stop loss to mode ticks in the same block as reversal, but prior to submission of the reversal order.
      I use "SetStopLoss(CalculationMode.Ticks, tickStop);" to set my initial stop and "SetStopLoss (CalculationMode.Price, stopPrice);" when I need to trail the stop. Are you saying there is a problem with this approach?

      Comment


        #4
        That approach is fine, but you need to be sure of the last value "set" for the stop loss when submitting any entry order.

        If you use mode Ticks, then stop loss is placed in relation to your entry price, and should always be on right side of market.

        If you use mode Price, then it submits a stop loss order exactly where you specify, and can be rejected if you specify an invalid price.

        The issue is control with the set statements, since they use the last value submitted. Before the submission of any entry order, you need to make sure that it's using mode Ticks for the correct initial placement.
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_RyanM View Post
          That approach is fine, but you need to be sure of the last value "set" for the stop loss when submitting any entry order.

          If you use mode Ticks, then stop loss is placed in relation to your entry price, and should always be on right side of market.

          If you use mode Price, then it submits a stop loss order exactly where you specify, and can be rejected if you specify an invalid price.

          The issue is control with the set statements, since they use the last value submitted. Before the submission of any entry order, you need to make sure that it's using mode Ticks for the correct initial placement.
          Can you please look at the contents of my output log with TraceOrders=true

          From what I can see, in the output window the events occur in the following order

          1. Long Postition is opened at 83.48
          2. Error is generated Immediately, and strategy sends CanceAllOrders & terminates itself
          3. My code is now trying to send profit target order
          4. My code is now trying to trail the position to 83.36 with setStopLoss(). 83.36 is 12 ticks below the long position, that is the correct side of the market.

          Firstly, there must be some kind of timing issue or something. Why do I get an error about a "Sell Stop" order before my code even issues a SetStopLoss()/setProfitTarget()? Seconly, this issue does not happen every time, only on occasion. Thirdly my trailing stop price is on the correct side of the market. Fourthly, the error mentions 83.53, where does that come from?

          What am I missing?
          Last edited by monpere; 08-08-2011, 12:10 PM.

          Comment


            #6
            Your strategy code controls the price of stop loss orders. If you send wrong values they're rejected. From the output I can see that there are two different calculation modes used in the same second, which means you're not controlling properly the price level of your Set orders. You need to simplify and debug your strategy.

            This reference sample can help with the technique to monitor the actual values used for Set orders:


            If you are unsure "the last value set" for your Set statements, then consider moving away from them and use instead ExitLongStop(), ExitShortStop()

            Set statements are convenient but for the most control you can use advanced handling concepts to submit equivalent orders.

            Ryan M.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_RyanM View Post
              Your strategy code controls the price of stop loss orders. If you send wrong values they're rejected. From the output I can see that there are two different calculation modes used in the same second, which means you're not controlling properly the price level of your Set orders. You need to simplify and debug your strategy.

              This reference sample can help with the technique to monitor the actual values used for Set orders:


              If you are unsure "the last value set" for your Set statements, then consider moving away from them and use instead ExitLongStop(), ExitShortStop()

              Set statements are convenient but for the most control you can use advanced handling concepts to submit equivalent orders.

              http://www.ninjatrader.com/support/h...r_handling.htm
              Yes, there are 2 different calculations used in the same second, one sets the initial stop with CalculationMode.Ticks, and since the is the CL is a fast moving market, the trailing stop kicks in immediately and tries to move the stop with CalculationMode.Price. You said there is nothing wrong with that approach, so why is this important now.

              Looking at the output from TraceOrders=true, which is an internal Ninja debugging mechanism, do you see any wrong price values? I also have print statements from OnPositionUpdate, do you see any wrong values in those? I don't see any wrong values, if you do, point them out, and I can see where they are coming from.
              Last edited by monpere; 08-08-2011, 01:48 PM.

              Comment


                #8
                Unfortunately I don't have anything additional to offer on your output. I can review this further if you attach your trace / log files. Please use Help > Mail to Support feature. Send Attn: RyanM and Reference this thread.
                Ryan M.NinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_RyanM View Post
                  Unfortunately I don't have anything additional to offer on your output. I can review this further if you attach your trace / log files. Please use Help > Mail to Support feature. Send Attn: RyanM and Reference this thread.
                  Yes sure, that is the standard NinjaTrader support brush off answer. Dude, I gave you all the internal NT debug info, and you see there is nothing wrong with the values. If I was sending wrong values to NT, would they not show up in your internal debug mechanism? I will give you my logs, and I'll never hear from you again. Forget it. I'll come up with a workaround myself, as I usually do.

                  Comment


                    #10
                    More information is available in your log / trace than you posted, and we will use this to gain a more complete picture of the sequence you're asking about. Requesting additional information is not a brush -off, but part of our standard support procedure. We also always respond same day email or forum.
                    Last edited by NinjaTrader_RyanM1; 08-08-2011, 02:19 PM.
                    Ryan M.NinjaTrader Customer Service

                    Comment


                      #11
                      TrailStop rejected CalculationMode.Ticks

                      Hi,
                      I am also having this problem in a strategy. When placing an order, the trailstop gets rejected. The order is placed in this way:

                      SetTrailStop(CalculationMode.Ticks,StopLossDistanc e);

                      Which produces logging like this:


                      10/11/2011 4:06:00 PM Calling dolong() from a simple trade entry of Signal=+1
                      10/11/2011 4:06:00 PM DoLong(), enter at limit=False
                      Reversing
                      10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      10/11/2011 4:06:00 PM .. forced Flattening of current position from any opposite signal
                      10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
                      10/11/2011 4:06:00 PM Ignore order amendment: Action=BuyToCover OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName=Buy to cover' FromEntrySignal='' Reason='Order already has this stop price/limit price/quantity'
                      DelayedEntryInfo 1, 0
                      10/11/2011 4:06:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00395/Sim101' Name='Profit target' State=Working Instrument='ES 12-11' Action=BuyToCover Limit price=1142 Stop price=0 Quantity=1 Strategy='AMSuiteTrader4' Type=Limit Tif=Gtc Oco='NT-00216-1394' Filled=0 Fill price=0 Token='e8236a7fde7d44daafd4a5ad4ab4845f' Gtd='1/12/2099 12:00:00 AM'
                      10/11/2011 4:06:00 PM Cancelled pending exit order, since associated position is closed: Order='NT-00394/Sim101' Name='Stop loss' State=Working Instrument='ES 12-11' Action=BuyToCover Limit price=0 Stop price=1248.75 Quantity=1 Strategy='AMSuiteTrader4' Type=Stop Tif=Gtc Oco='NT-00216-1394' Filled=0 Fill price=0 Token='3201377710aa445eb9f29c3df7b9613e' Gtd='1/12/2099 12:00:00 AM'
                      10/11/2011 4:06:00 PM (10/11/2011 4:05:57 PM) DoLimitEntry() with data 1, 0 AT MARKET
                      10/11/2011 4:06:00 PM Entered internal PlaceOrder() method at 10/11/2011 4:06:00 PM: BarsInProgress=0 Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='MACDZeroCross_Long' FromEntrySignal=''
                      10/11/2011 4:06:00 PM Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=385 Currency=0 Simulated=False
                      10/11/2011 4:05:57 PM Entered internal SetStopTarget() method: Type=TrailStop FromEntrySignal='' Mode=Ticks Value=20 Currency=0 Simulated=False
                      **NT** Strategy 'AMSuiteTrader4/00890ac470554df59a2449d3d90586d1' submitted an order that generated the following error 'OrderRejected'. Strategy has sent cancel requests, attempted to close the position and terminated itself.
                      10/11/2011 4:05:57 PM CancelAllOrders: BarsInProgress=0
                      10/11/2011 4:05:58 PM Entered internal PlaceOrder() method at 10/11/2011 4:05:58 PM: BarsInProgress=0 Action=Sell OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Close' FromEntrySignal=''
                      10/11/2011 4:05:59 PM Disable() called: strategy disabled
                      **NT** Disabling NinjaScript strategy 'AMSuiteTrader4/00890ac470554df59a2449d3d90586d1'


                      This makes no sense as Ninja is supposed to correctly place a TrailStop.
                      I even have gone to the trouble of getting flat before I enter the next position, instead of instantly reversing. No change in the problem.

                      Please help. I can send you the trace file from the above incident if you like.
                      Cheers,
                      saltminer

                      Comment


                        #12
                        Hi saltminer,

                        Sure, please send trace and log files to my attention to support 'at' ninjatrader 'dot' com.
                        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
                        670 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        379 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by Mindset, 02-09-2026, 11:44 AM
                        0 responses
                        111 views
                        0 likes
                        Last Post Mindset
                        by Mindset
                         
                        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                        0 responses
                        575 views
                        1 like
                        Last Post Geovanny Suaza  
                        Started by RFrosty, 01-28-2026, 06:49 PM
                        0 responses
                        582 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X