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

Set Stoploss order, Cancel Order

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

    Set Stoploss order, Cancel Order

    Hello,

    I am on the way to implement custom strategy and a part to work with orders is new for me.
    And I need help of experienced guys.

    Let say, I have potential sygnal to enter the market (see attached image bellow).
    The sygnal bar is colorized.

    Let say we have bullish situation.
    When sygnal bar appears, on break up of signal bar I put buy stop order.
    And I would like to know :
    * how to put buy stop order?
    * how to put sell stop order (stoploss) , when buy stop order filled?
    * how to remove / cancel buy stop order when price break specified level to cancel the order? (see pic. bellow)

    As examples what i want to do I described in att. file.
    Attached Files

    #2
    Hello Akushyn,

    Thank you for your post.

    You would want to EnterLongStop() method to place a Stop Market order.
    http://www.ninjatrader.com/support/h...erlongstop.htm

    Additionally, you would want to use IOrder object handling for this so you can cancel working/accepted orders.
    http://www.ninjatrader.com/support/h...r_handling.htm

    To set Stop Loss orders you can use the Set() methods for this in the Initialize() Method -
    http://www.ninjatrader.com/support/h...etstoploss.htm

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Cal View Post
      Hello Akushyn,

      Thank you for your post.

      You would want to EnterLongStop() method to place a Stop Market order.
      http://www.ninjatrader.com/support/h...erlongstop.htm

      Additionally, you would want to use IOrder object handling for this so you can cancel working/accepted orders.
      http://www.ninjatrader.com/support/h...r_handling.htm

      [/URL]

      Let me know if I can be of further assistance.
      Thank you for the answer and for your quick reply.

      Could you please, send me some exapmle how to use EnterLongStop with next approach?
      I think , the parameter liveUntilCancelled is what I am looking for...

      Code:
      EnterLongStop(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double stopPrice, string signalName)
      To set Stop Loss orders you can use the Set() methods for this in the Initialize() Method -
      [URL="http://www.ninjatrader.com/support/helpGuides/nt7/index.html?setstoploss.htm"]http://www.ninjatrader.com/support/helpGuides/nt7/index.html?setstoploss.htm
      Cant get the thought about Initialize() method. The issue is that :
      * I know the stoploss price only when potential sygnal appear

      Comment


        #4
        Akushyn,

        I am attaching two samples that will help get setup in the right direction.

        The first one will show you how to setup protective orders for your Entry using the IOrder and OnOrder and OnExecution methods -
        http://www.ninjatrader.com/support/f...ead.php?t=7499

        The second one will show you how to use the CancelOrder() method -
        http://www.ninjatrader.com/support/f...ad.php?t=18890
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          Very useful information for me.
          Thank you very much.

          Hope, I can ask some more questions if I have ones.

          --
          Greetings, Andriy

          Comment


            #6
            Hello,

            I saw your examples and even more by link: http://www.ninjatrader.com/support/f...splay.php?f=30

            Got almoust everything , except this part of code:
            See bold text bellow right .
            Can't understand how OrderState can be Canceled and Filled at the same time ?

            Code:
            if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || [B](execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)[/B])
            {
                             // .... do smth
            }

            Comment


              #7
              Akushyn,

              This is an OR statement. The || represent OR while && represent AND

              If the order was filled OR partfilled OR the order was cancelled and had fills
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                How to check inside code the type of filled order (Long or Short) ?
                Cause, the price of ProtectOrder and TargetOrder will be different...

                smth like.:

                if (entryOrder.Type == OrderType.Long)
                // do smth
                else if (entryOrder.Type == OrderType.Short)
                // do smth
                Last edited by akushyn; 09-03-2014, 12:59 PM.

                Comment


                  #9
                  Akushyn,

                  That's what the IOrder object is for.

                  You can name these how you want when doing your entry orders.

                  IOrder EntryLong = EnterLong();

                  Then in OnOrderUpdate(IOrder order)

                  if(order == EntryLong && order.OrderState == OrderState.Filled)
                  {
                  // Do something here
                  }
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Thanks a lot!, I got the point .

                    Have another question...

                    In my strategy, to enter the market I check conditions every time when bar closed. For this I set property OnBarClose = true in Initialize() method
                    But when I am in position, I have to check breakeven conditions every tick of bar.

                    How to be deal with two different ways ? (on bar close & every tick)

                    Comment


                      #11
                      Akushyn,

                      You will need to use CalculateOnBarClose set to false for the every tick portion but you can use the bool FirstTickOfBar to get when a new bar is created, much like running CalculateOnBarClose true.

                      http://www.ninjatrader.com/support/h...ttickofbar.htm
                      Cal H.NinjaTrader Customer Service

                      Comment


                        #12
                        Is there available smth like last tick of bar ?
                        cause when gap appear, it will be not so good to manage entry point
                        Last edited by akushyn; 09-04-2014, 12:40 PM.

                        Comment


                          #13
                          Akushyn,

                          There is not a last tick of bar method available.
                          Cal H.NinjaTrader Customer Service

                          Comment


                            #14
                            Hello,

                            Thank you for the answer.
                            When I add a strategy to the chart and then press 'Enable' I see that all drawing objects are using only last points and not points from history.
                            The issue looks like in picture1-3 in attached files.

                            Then, when I press refresh strategy (F5) and OK, then all objects draws as needed.
                            How could I fix this issue?
                            Attached Files

                            Comment


                              #15
                              akushyn, what object types exactly are causing you the issue? Are you drawing them by time or bar index based? From which event / method are the items drawn?
                              BertrandNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by fredericlebre, Today, 01:19 AM
                              0 responses
                              1 view
                              0 likes
                              Last Post fredericlebre  
                              Started by TraderJA, Today, 12:06 AM
                              0 responses
                              4 views
                              0 likes
                              Last Post TraderJA  
                              Started by SnailHorn, Yesterday, 10:49 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post SnailHorn  
                              Started by naanku, Yesterday, 07:25 PM
                              0 responses
                              8 views
                              0 likes
                              Last Post naanku
                              by naanku
                               
                              Started by milfocs, Yesterday, 07:23 PM
                              0 responses
                              6 views
                              0 likes
                              Last Post milfocs
                              by milfocs
                               
                              Working...
                              X