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

setstoploss

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

    setstoploss

    using the setstoploss function is it possible to get the order to be a stoplimt order rather than a stop market order

    if this is not possible is it possible to have an entry condition
    then automatically have SetProfitTarget and ExitStopLimit tied together with the same OCO functionality that goes with SetProfitTarget and SetStopLoss

    #2
    Hello fiddy,

    Thank you for writing in.

    You would not be able to utilize a SetProfitTarget() and ExitStopLimit() at the same time as the internal order handling rules will prevent this. Rather, you would need to place an ExitLongLimit()/ExitShortLimit() (for the profit target) and ExitLongStopLimit()/ExitShortStopLimit() (for the stop loss as a limit order).

    For more information about these methods, please take a look at the following links below:
    ExitLongLimit(): http://ninjatrader.com/support/helpG...tlonglimit.htm
    ExitShortLimit(): http://ninjatrader.com/support/helpG...shortlimit.htm

    ExitLongStopLimit(): http://ninjatrader.com/support/helpG...gstoplimit.htm
    ExitShortStopLimit(): http://ninjatrader.com/support/helpG...tstoplimit.htm

    If either order is hit, the other is automatically cancelled as the associated position will be closed.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      thanks Zachary

      Is it possible to access the check what the current stop price is in the ExitLongStopLimit and ExitShortStopLimit? Do i need to create my own stop variable to reference?

      i want to reference the stop price so that i check to see that price hasnt jumped the stop limit

      for example:

      if ( Close[0] < StopPrice)
      {
      ExitLong()

      }

      Comment


        #4
        Hello fiddy,

        What you could do is check the stop price once the particular order is submitted/updated by using OnOrderUpdate() and then setting a variable to this value.

        As an example:
        Code:
        private double stopPrice = 0;
        
        protected override void OnOrderUpdate(IOrder order)
        {
             // make sure to change "myStopOrder" to the signal name of your stop order
             if (o.Name == "myStopOrder" && o.OrderState == OrderState.Accepted)
             {
                  stopPrice = o.StopPrice;
             }
        }
        More information about OnOrderUpdate() can be found here: http://ninjatrader.com/support/helpG...rderupdate.htm

        Please, let us know if we may be of further assistance.
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          so that i can use a stoplimit and not use setstoploss and setprofittarget i have chnage my code to below.

          however once the entry order has been filled the exitlonglimit and exitlongstoplimit orders have not been placed. have i missed something?


          if (condition)
          {
          entryOrder = EnterLongLimit();
          ExitLongLimit(TargetLine);
          ExitLongStopLimit(StopLine);
          }

          Comment


            #6
            Hello fiddy,

            This occurs because your position doesn't exist yet by the time your Exit() methods are being called. Exit() orders will not be placed when a position doesn't exist.

            What you can do is do if have a check in OnBarUpdate() to check if you're currently in a long position. If so, then submit the Exit() methods.

            Example:
            Code:
            // if we're currently in a long position, call the Exit() methods
            if (Position.MarketPosition == MarketPosition.Long)
            {
                 // exit methods
            }
            Please, let us know if we may be of further assistance.
            Zachary G.NinjaTrader Customer Service

            Comment


              #7
              how do you tied the two orders together to make them OCO or is this automatic?


              if (Position.MarketPosition == MarketPosition.Long)
              {
              exitlonglimit()
              exitlongstoplimit()
              }

              Comment


                #8
                Hello fiddy,

                The orders will not be tied to each other, however the other order will automatically cancel once the position no longer exists.

                I would suggest setting the TraceOrders property to true in your strategy. This will allow you to view valuable output related to strategy submitted orders through Tools > Output window - TraceOrders.

                More information about using TraceOrders can be found on this particular post on the support forum: http://ninjatrader.com/support/forum...63&postcount=1

                You will see that once you exit, you will see a message akin to . . .
                Code:
                Cancelled pending exit order, since associated position is closed
                . . . for your other order.

                Please, let us know if we may be of further assistance.
                Zachary G.NinjaTrader Customer Service

                Comment


                  #9
                  thanks Zachary

                  Would this be best placed under onpositionupdate rather than onbarupdate so that the exit orders are placed immediately once position is entered?

                  protected override void OnPositionUpdate(IPosition position)

                  if (Position.MarketPosition == MarketPosition.Long)
                  {
                  exitlonglimit()
                  exitlongstoplimit()
                  }

                  Comment


                    #10
                    Hello fiddy,

                    It would be better to place your Exit() methods within OnExecution() so they can be called once your entry fills. OnExecution() is called on an incoming execution (fill).

                    More information about the OnExecution() method can be found in the NinjaTrader help guide here: https://ninjatrader.com/support/help...nexecution.htm

                    Please, let us know if we may be of further assistance.
                    Zachary G.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by bortz, 11-06-2023, 08:04 AM
                    47 responses
                    1,608 views
                    0 likes
                    Last Post aligator  
                    Started by jaybedreamin, Today, 05:56 PM
                    0 responses
                    9 views
                    0 likes
                    Last Post jaybedreamin  
                    Started by DJ888, 04-16-2024, 06:09 PM
                    6 responses
                    19 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by Jon17, Today, 04:33 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post Jon17
                    by Jon17
                     
                    Started by Javierw.ok, Today, 04:12 PM
                    0 responses
                    16 views
                    0 likes
                    Last Post Javierw.ok  
                    Working...
                    X