Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Buy stop or buy stop limit orders can't be placed below the market

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

    Buy stop or buy stop limit orders can't be placed below the market

    ​​Hi,

    I am developing a strategy and for submitting TP and SL in UnManaged Mode using the following code but get "Buy stop or buy stop limit orders can't be placed below the market"

    Code:
    // For Buy order
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.StopMarket, execution.Order.Filled, 0, execution.Order.AverageFillPrice - 90* TickSize, strOCOID, "BuyStop");
    SubmitOrderUnmanaged(0, OrderAction.Sell, OrderType.Limit, execution.Order.Filled, execution.Order.AverageFillPrice + 40* TickSize, 0, strOCOID, "BuyTarget");
    
    //For Sell order
    
    SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.StopMarket, execution.Order.Filled, 0, execution.Order.AverageFillPrice + 40* TickSize, strOCOID, "SellStop");
    
    SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.Limit, execution.Order.Filled, execution.Order.AverageFillPrice - 90* TickSize, 0, strOCOID, "SellTarget");
    I am trying to get a functionality of the below ATM setting(Stop loss =90 and Profit =40)

    Click image for larger version

Name:	AshkanATM1.JPG
Views:	35
Size:	28.5 KB
ID:	1128298
    Attached Files

    #2
    Hello bosajin,

    Thank you for your post.

    I've plugged your stop and targets into a Unmanaged template example and they seem to be working as I'd expect - I'm not seeing this throw errors. I've attached my test script below. Do you see the same error occurring with this test script?

    Thanks in advance; I look forward to assisting you further.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi Kate ,

      Thanks for sample code .

      I have a problem and would appreciate if you help me out to solve it.

      Expectation : I would like to close an order in next bar if it was not closed by stop order or profit order.
      Actual : I still have an open position when trying to close an order with a reverse order.


      Changed sample code : TestStopTargetUnmanaged.cs

      Video: http://sc.com.ly/show/PkfXwGyz4HpVrv3jhIBxq15N9UcZQDbm

      Click image for larger version  Name:	Open Order.JPG Views:	0 Size:	121.9 KB ID:	1129383

      Comment


        #4
        Hello bosajin,

        Thank you for your reply.

        You could try using BarsSinceEntryExecution to check how many bars have elapsed since the order was entered, and if so exit the position:

        https://ninjatrader.com/support/help...yexecution.htm

        Code:
        if(Position.MarketPosition != MarketPosition.Flat)
        {
        if (BarsSinceEntryExecution() > 1)
        {
            //your exit logic goes here
        }
        }
        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          Hi Kate,

          Thank you for swift response .
          As you can see in the code , I want to close position when bar is closed and actually using IsFirstTickOfBar because of Calculate = Calculate.OnEachTick which works for me.
          The issue is closing position right away and open an new position.
          This is reason I am using Unmanaged approach(also your support team has recommended it already due to the Rithmic in-flight execution problem[the broker feed do not update the position as flat]) and I don't want to have an open position without TP/SL as you can see in the attachment.

          Please let me know if you need more information.

          Comment


            #6
            Hello bosajin,

            Thank you for your reply.

            The example in my previous post in this thread is simply showing that those orders work as written. That particular strategy is not optimized for tracking the strategy position as would be necessary with Rithmic because of the issue with the order of Order/Position/Execution updates - it was simply meant to illustrate that there's not an issue with the orders themselves as shown in your initial post in this thread.

            That being said, we're working on a better example for you. With the US Thanksgiving holiday this week, it may take some time to complete, so we'll let you know when that's available for you.

            Thanks in advance; I look forward to assisting you further.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Hi Kate,

              Thank you for your response.

              Your sample does not work for partial fill. would you please provide me with an another example.

              Comment


                #8
                Hello bosajin,

                Thank you for your reply.

                As I mentioned in my previous post, we were working on an updated example that would work with Rithmic. I've attached that example below.

                Please let us know if we may be of further assistance to you.
                Attached Files
                Kate W.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by daven, Today, 09:49 AM
                1 response
                4 views
                0 likes
                Last Post NinjaTrader_Eleanore  
                Started by omermirza, 01-15-2021, 01:15 PM
                13 responses
                115 views
                0 likes
                Last Post NinjaTrader_Jim  
                Started by Island_Boy_Trading, Today, 07:39 AM
                2 responses
                14 views
                0 likes
                Last Post Island_Boy_Trading  
                Started by cmarkb, Today, 07:19 AM
                1 response
                11 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Started by wjadevries, Today, 03:29 AM
                1 response
                16 views
                0 likes
                Last Post NinjaTrader_Jim  
                Working...
                X