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

Breakout Strategy - Ninjatrader 8 - Unmanaged Order

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

    Breakout Strategy - Ninjatrader 8 - Unmanaged Order

    Hi,

    i working on a breakout strategy using stop long and stop short orders to get into the market on a breakout. I want to keep a position until its either stopped out or reached its target. For example: I also want to keep a long order when the the short stop entry is reached.

    This is what i did so far:

    Code:
    longStopOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopMarket, 1, 0, high, "longStop", "lStop");
    					longStopOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.MIT, 1, 0, high-100, "longStop", "lStopLoss");
    					longStopSL= SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.MIT, 1, 0, high+250, "longStop", "lStopTP");
    
    					longStopTP = SubmitOrderUnmanaged(1, OrderAction.Sell, OrderType.StopMarket, 1, 0, low, "shortStop", "sStop");
    Somehow those orders are mixed even though iam using the same OCO string. Can someone point me into the right direction?
    Last edited by ipmagn; 03-08-2016, 07:49 AM.

    #2
    Hello ipmagn,

    Thank you for your post.

    Please clarify on what is getting mixed up. Can you provide details on what is occurring that you are not expecting?
    The code looks correct for what you are looking for based on your inquiry.

    Comment


      #3
      Hey,

      thank you for your response.

      I just uploaded a picture showing the issue. I would expect a long order to be opened here. But a short order called lStopLoss is opened instead which i would expect to be the stop loss order of my buy order.

      If i would go without the stop loss and take profit order something else would happen. Lets say the buy stop order was filled and the market is coming down reaching the sell stop price. Instead of opening a new sell order it just closes my buy order.

      Is using a stop loss and take profit only possible when using a ATM strategy?
      Attached Files
      Last edited by ipmagn; 03-08-2016, 09:05 AM.

      Comment


        #4
        Hello,

        Thank you for the reply.

        You can use StopLoss and ProfitTargets outside of a ATM strategy, because you are using the Unmanaged Approach you would need to create the logic for these orders and submit them yourself.

        Was the entry Filled prior to submitting the other orders? On the chart I can see the Exit On Close order, but I do not see where the entry was filled. Next I see the following order was executed:

        longStopOrder = SubmitOrderUnmanaged(0, OrderAction.SellShort, OrderType.MIT, 1, 0, high-100, "longStop", "lStopLoss");

        I would expect this in the case the Long order did not yet fill but the short order which was submitted at the exact same time did fill.

        Are you trying to instead submit the Stop and Target once the Long order has filled?


        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Thank you Jesse.

          So i would have to implement the OnExecutionUpdate() method and wait for an order to be filled before opening sl and tp orders?

          Is it possible to be long and short at the same time?

          Comment


            #6
            Hello,

            Yes in most cases that can aid in creating logic that would be executed once a Order has Filled like an Entry that needs a Target and Stop. We have a sample of this here although this is using the managed approach it is the same concept: http://ninjatrader.com/support/forum...ead.php?t=7499

            Regarding being Long and Short, are you referring to a Bracket where you have a Long and Short entry Pending? If you Enter long and Enter short you would be flat so I am not sure I have understood the question fully.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Ok i understand now. Thank you both very much.

              About beeing long and short at the same time. Yes, some Broker outside the US support that by threating positions independently.Being Long and Short would not mean to be flat in that case.

              Comment


                #8
                sl and tp order is canceled right after beeing accepted

                Hey guys,

                still having problems here. Iam opening a sell stop order which gets filled at some point. A buy stop order is opened and accepted right after that. Iam using the OnExecutionUpdate() method as you can see below.

                But shortly like a milli second after that this short order is getting canceled again. Am I using the wrong ordertype or why is that happening? The strategy analyser marks this order as good till cancel so it should not be cancelled right away.

                Code:
                protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
                		{
                		   
                		    if (execution.Order != null && execution.Order.OrderState == OrderState.Filled) {				
                				if(o.OrderAction == OrderAction.Sell) {
                					shortSL = SubmitOrderUnmanaged(0, OrderAction.BuyToCover, OrderType.StopMarket, 1, 0, price+100, "short", "sl");

                Comment


                  #9
                  Hello,

                  Thank you for the question.

                  I do not see anything directly in this portion of code that may cause the cancel, do you have any CancelOrder commands used in other parts of the logic?

                  I would be unsure without a more complete view of what is happening, likely you would need to use Print statements to map out how the logic of the orders is being executed in the case you are using CancelOrder anywhere.

                  I look forward of being of further assistance.
                  JesseNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by judysamnt7, 03-13-2023, 09:11 AM
                  4 responses
                  59 views
                  0 likes
                  Last Post DynamicTest  
                  Started by ScottWalsh, Today, 06:52 PM
                  4 responses
                  36 views
                  0 likes
                  Last Post ScottWalsh  
                  Started by olisav57, Today, 07:39 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post olisav57  
                  Started by trilliantrader, Today, 03:01 PM
                  2 responses
                  21 views
                  0 likes
                  Last Post helpwanted  
                  Started by cre8able, Today, 07:24 PM
                  0 responses
                  10 views
                  0 likes
                  Last Post cre8able  
                  Working...
                  X