Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

type of SetProfitTarget

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

    type of SetProfitTarget

    Hi, I'm toying with passing some order methods to an externl class and the simpler ones, like EnterLong(), work out okay. However, I'm stuck with passing SetProfitTarget() and SetStopLoss() methods as I can't determine their return types. It's neither IOrder, not bool, nor void, so what is it then? The docs are silent about this...

    #2
    They have no return type. If you wish max control over such things like profit targets and stop losses we recommend you to use ExitLongStop() or ExitLongLimit() as an IOrder via the OnOrderUpdate(), OnExecution() etc methods.

    Please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=7499

    This reference may be of some use too: http://www.ninjatrader-support.com/v...ead.php?t=5790
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh I'll look into that

      Comment


        #4
        For some reason it doesn't work:

        protected override void OnBarUpdate() {
        .....
        string name = "Buy" + CurrentBar;
        IOrder order = EnterLong( 1, name );
        ExitLongLimit( 1, Close[0] + 2, name + "_lmt" , name );
        // I also tried ExitLongLimit( 1, Close[0] + 2, name + "_lmt" , order.Name );
        }

        Is this because I am using it in OnBarUpdate() ?

        Comment


          #5
          What part doesn't work? Please provide the error message from the Control Center logs and the TraceOrders output.

          It is recommended you create the IOrder object in the variables section and set it to null as demonstrated in the reference sample. Also, Close[0] + 2 is not the close price and 2 ticks its the close price and 2. You may want to use Close[0] + 2 * TickSize if you were intending it to be ticks.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Hi Josh, thanks for the hint about the price values, turned out that it was setup properly. What goes wrong is the limit order is not being placed after position has been entered.

            I've declared the IOrder variable as a class member and re-run the strategy with traceOrder enabled. Here's the output for the first two trades in a session (basically, all the error messages I am getting after the second error are the same as the second one, the first one being different):

            7/10/2008 10:31:00 AM Entered internal PlaceOrder() method at 7/10/2008
            10:31:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy0' FromEntrySignal=''

            7/10/2008 10:31:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:31:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=664.5 StopPrice=0 SignalName='Buy0_Lmt' FromEntrySignal='Buy0'

            7/10/2008 10:31:00 AM Ignored PlaceOrder() method: Action=Sell OrderType=Limit Quantity=1 LimitPrice=664.5 StopPrice=0 SignalName='Buy0_Lmt' FromEntrySignal='Buy0' Reason='This was an exit order but no position exists to exit'

            7/10/2008 10:32:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Buy OrderType=Market Quantity=1 LimitPrice=0 StopPrice=0 SignalName='Buy1' FromEntrySignal=''

            7/10/2008 10:32:00 AM Entered internal PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=665.4 StopPrice=0 SignalName='Buy1_Lmt' FromEntrySignal='Buy1'

            7/10/2008 10:32:00 AM Ignored PlaceOrder() method at 7/10/2008 10:32:00 AM: Action=Sell OrderType=Limit Quantity=1 LimitPrice=665.4 StopPrice=0 SignalName='Buy1_Lmt' FromEntrySignal='Buy1' Reason='SignalName does not have a matching FromEntrySignal to exit'
            .....................

            These traces are the same when I use "name" or "order.Name" as the fromSignalName variable.
            Last edited by billitin; 07-10-2008, 10:07 PM.

            Comment


              #7
              This is the source of your problems. 'This was an exit order but no position exists to exit'

              You need to now go find where your strategy is exiting your position beforehand.

              In general you would simply just do this as your lines of pseudocode:
              condition 1
              EnterLong()
              if (Position.MarketPosition == MarketPosition.Long)
              ExitLongLimit()
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                I've tried wrapping up ExitLongLimit() in the condition for open market position and indeed it works. However, a check for an existing position means that I can't attach a stop/limit to an order when it's entered all at the same time and I'll have to do such attachment outside of onBarUpdate(). Then this is inconvenient considering I may be entering several different long positions on one bar close. How would I create a bracket order in one go?

                Comment


                  #9
                  OnBarUpdate() is inherently not the best suited for bracket orders.

                  If absolute speed is what you want you want to do this in the OnExecution/OnOrderUpdate() methods as demonstrated in the reference sample.
                  Josh P.NinjaTrader Customer Service

                  Comment


                    #10
                    great, that works just fine, thanks for your help

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Jeremytang, 07-14-2018, 06:45 PM
                    21 responses
                    439 views
                    0 likes
                    Last Post mav8rick  
                    Started by LeonK, Yesterday, 09:26 PM
                    1 response
                    7 views
                    0 likes
                    Last Post bltdavid  
                    Started by NicholasJoannette, Yesterday, 03:01 PM
                    2 responses
                    11 views
                    0 likes
                    Last Post NicholasJoannette  
                    Started by rach1994, Yesterday, 12:20 PM
                    1 response
                    35 views
                    0 likes
                    Last Post bltdavid  
                    Started by litamm89, Yesterday, 11:00 AM
                    5 responses
                    21 views
                    1 like
                    Last Post rafael_delima86  
                    Working...
                    X