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

SetTrailStop Unmanaged

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

    SetTrailStop Unmanaged

    Hello,

    I need to submit a TrailStopLoss in an Unmanaged order. In the Documentation however there doesn't appear to be a corresponding method.

    How do I achieve this?

    #2
    Hello cocopod,

    To use strategy commands from the managed approach such as SetTrailStop() or SetProfitTarget() or EnterLong() you must be using the manage approach.

    http://www.ninjatrader.com/support/h...d_approach.htm


    If you use the unmanaged approach, you will need to submit an exit stop or stop limit order and use custom logic with ChangeOrder() to have the order trail.

    http://www.ninjatrader.com/support/h...hangeorder.htm

    http://www.ninjatrader.com/support/h...d_approach.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Reinventing the wheel

      Hi there,



      I have seen a number of posts asking for guidance on this but for some reason I feel like I'm reinventing the wheel. Surely you have sample code for this?

      Currently I'm using "SubmitOrder" to create the unmanaged order.

      You seem to be suggesting that I create "an exit stop or stop limit order" that from my limited experience has no UnManaged method to facilitate the process.

      Are you saying that I simply create another order -for example "StopOrder" again using the SubmitOrder command and then use code to get this to trail the main order as in the code below?




      protected override void OnBarUpdate()
      {
      // Raise stop loss to breakeven when you are at least 4 ticks in profit
      if (stopOrder != null && stopOrder.StopPrice < Position.AvgPrice && Close[0] >= Position.AvgPrice + 4 * TickSize)
      ChangeOrder(stopOrder, stopOrder.Quantity, stopOrder.LimitPrice, Position.AvgPrice);
      }

      Comment


        #4
        Hi cocopod,

        Does your code require you use the unmanaged approach? You may find it easier to use the managed approach.

        Yes, you will need to use SubmitOrder() to submit orders such as buy market, sell stop, or sell stop limit.

        For example to place a sell stop limit as an exit order:

        In #region Variables:
        private IOrder exitOrder = null;

        In a strategy method such as OnBarUpdate:
        exitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.StopLimit, 1, Close[0]-30*TickSize, Close[0]-10*TickSize, "", "Enter Long");

        SubmitOrder(int barsInProgressIndex, OrderAction orderAction, OrderType orderType, int quantity, double limitPrice, double stopPrice, string ocoId, string signalName)
        http://www.ninjatrader.com/support/h...ubmitorder.htm

        This would place a sell stop limit 10 ticks below the current price with the limit placed at 30 ticks below the current price (to try and guarantee a fill).

        Then to change the order:
        ChangeOrder(exitOrder, 1, Close[0]-20*TickSize, Close[0]-5*TickSize);
        ChangeOrder(IOrder iOrder, int quantity, double limitPrice, double stopPrice)
        http://www.ninjatrader.com/support/h...hangeorder.htm


        There are not any reference samples that use the unmanaged approach, however, there is a strategy on the forum that uses the unamaged approach called CamarillaPointsATS.
        http://www.ninjatrader.com/support/f...php?linkid=571
        Last edited by NinjaTrader_ChelseaB; 11-10-2014, 01:21 PM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Very Helpful

          Chelsea,

          My understanding is that the StopLoss will have to be created using OnExecution as this will guarantee it will only happen when the entryOrder is created. Is this approach correct? See my code below

          protected override void OnExecution(IExecution execution)
          {

          if (entryOrder != null && entryOrder == execution.Order)
          // Trail Stop for order
          {stopOrder = SubmitOrder(0, OrderAction.Sell, OrderType.StopLimit, 1, Close[0]-10*TickSize, Close[0]-1*TickSize, "", "Enter Long");

          }

          Comment


            #6
            Hi cocopod,

            If you are using the managed approach, yes, placing the SetStopLoss in OnExecution will trigger as the entry order fills.

            However, by using SetStopLoss, the stop loss will not be submitted until the entry order fills anyway and this will not make any difference. If you use SetStopLoss and there is no position, no exit order is submitted.

            If you place orders using SubmitOrder() to submit an exit, this must to go into OnExecution if you would like the protective exit order submitted when the entry fills.
            Thus, its more import that protect orders be submitted in OnExecution when not using SetStopLoss.
            Chelsea B.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Yasharandom, Today, 07:45 AM
            0 responses
            5 views
            0 likes
            Last Post Yasharandom  
            Started by llanqui, Yesterday, 09:59 AM
            4 responses
            24 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by smartromain, 03-13-2024, 01:42 AM
            5 responses
            95 views
            0 likes
            Last Post AndreiBig  
            Started by Noerclou, Today, 04:55 AM
            0 responses
            5 views
            0 likes
            Last Post Noerclou  
            Started by ThoriSten, Today, 03:56 AM
            0 responses
            6 views
            0 likes
            Last Post ThoriSten  
            Working...
            X