• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Managed positions, stop loss and targets

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

    Managed positions, stop loss and targets

    I am using the managed approach for strategy positions. Let's say I take a long position and place the following order:

    entryOrder = baseStrategy.EnterLong( 0, Constants.contractQuanity, entrySignalName );

    Once entryOrder fills (caught in OnExecution), I place a stop and target order:

    stopOrder = baseStrategy.ExitLongStop( 0, true, execution.Order.Filled, stopPrice, "StopLoss", entrySignalName );

    targetOrder = baseStrategy.ExitLongLimit( 0, true, execution.Order.Filled, targetPrice, "ProfitTarget", entrySignalName );

    If the stopOrder fills, will the targetOrder automatically be cancelled? And, vice versa, if the targetOrder fills, will the stopOrder automatically cancel, or do I need to do something further?

    #2
    Hello risingfire,

    Thanks for your post and question regarding managed orders in strategies.

    There are two ways to handle OCO functionality in Managed orders:

    1) To use the simplified OCO functionality of the managed approach you would need to use the Set methods in the initialize section.

    From the help guide (complete section linked below):
    A few key points:
    • Orders are submitted as live working orders when a strategy is running in real-time
    • *Profit targets, stop loss and trail stop orders are submitted immediately as entry orders are filled and are also OCO tied
    • Order changes and cancellations are queued in the event that the order is in a state where it can't be cancelled or modified
    • By default, orders submitted via Entry() and Exit() methods automatically cancel at the end of a bar if not re-submitted

    * Via the SetProfitTarget(), SetStopLoss() and SetTrailStop() methods

    Here is the link to the help section on managed approach: http://www.ninjatrader.com/support/h...d_approach.htm

    2) Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnExecution() method is updated whenever you receive an execution or a fill on your orders. This method provides you the fastest possible submission of protective orders.
    Here is a reference sample that demonstrates this: http://www.ninjatrader.com/support/f...ead.php?t=7499

    Please let me know if I can be of further assistance.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Paul View Post
      There are two ways to handle OCO functionality in Managed orders:

      1) To use the simplified OCO functionality of the managed approach you would need to use the Set methods in the initialize section.

      2) Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods.
      Thanks, Paul. I was using your approach in #2. But I ran into an issue where I wanted to scale out profit and was uncertain how to accomplish that using OnExecution() to track order fills. Since this is an OCO and I have two profit targets, I was not sure what would happen when the first target was reached. Would the stop be cancelled or would I control this by having two different signal names?

      I'm looking into the scale out strategy example now that uses Sets (option #1 above).

      But am wondering how profit scaling could be accomplished using OnExecution()?

      Comment


        #4
        Something is not quite right using the managed Set() methods.

        I am entering the orders as indicated in the SampleScaleOut strategy example. I have 3 contracts for the profit trade and leave 2 contracts for a runner trade.

        Code:
        // These Set methods will place Profit Target and Stop orders for our entry orders. Profit Target order is only tied to our
        // order named profitEntrySignalName. This is the crucial step in achieving the following behavior. 
        // 		If the price never reaches our Profit Target, both long positions will be closed via our Stop.
        // 		If the price does hit our Profit Target, part of our position will be closed leaving the remainder to be closed by our Stop.
        			
        SetProfitTarget( profitEntrySignalName, CalculationMode.Ticks, initialTargetTicks );
        SetStopLoss( CalculationMode.Ticks, initialStopLossTicks );
        
        EnterShort( Constants.timeframeIndexLTF, profitContracts, profitEntrySignalName );
        EnterShort( Constants.timeframeIndexLTF, runnerContracts, runnerEntrySignalName );
        And once my profit target is hit, I reset the stoploss to break even. I monitor for the target profit trade in OnExecution():

        Code:
        if ( ((execution.Order.OrderState == OrderState.Filled) || (execution.Order.OrderState == OrderState.PartFilled)) && (execution.Name.IndexOf("Profit target") != -1) )
        	{
        		SetStopLoss( CalculationMode.Price, newStopLossPrice );
        	}
        However, it looks like the stoploss is being cancelled and my reset never occurs.

        I also notice that the "name" of the profit target object is not the name I gave it (stored in profitEntrySignalName). Whereas mine was "Tigger setup on 1 Minute (Target Profit Trade)", it looks like NinjaTrader made it "Profit target".

        Are the profit targets and stops not being tied correct to the entries?

        Here is a log of what transpires in OnExecution() and and OnOrderUpdate():

        Code:
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Target Profit Trade)' State=PendingSubmit Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=3 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='58ab612511634435940ad57ed112cc22' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Target Profit Trade)' State=Accepted Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=3 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='58ab612511634435940ad57ed112cc22' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Target Profit Trade)' State=Working Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=3 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='58ab612511634435940ad57ed112cc22' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=PendingSubmit Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=3 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=Accepted Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=3 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Profit target' State=PendingSubmit Instrument='ES 06-14' Action=BuyToCover Limit price=1883.75 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='84bfbc64efb04b77af639961d0e42217' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Profit target' State=Accepted Instrument='ES 06-14' Action=BuyToCover Limit price=1883.75 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='84bfbc64efb04b77af639961d0e42217' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Profit target' State=Working Instrument='ES 06-14' Action=BuyToCover Limit price=1883.75 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='84bfbc64efb04b77af639961d0e42217' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Target Profit Trade)' State=Filled Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=3 Type=Market Tif=Gtc OverFill=False Oco='' Filled=3 Fill price=1884.5 Token='58ab612511634435940ad57ed112cc22' Gtd='1/1/0001 12:00:00 AM'
        
        Time: 5/22/2014 9:31:00 AM OnExecution: Execution=Instrument='ES 06-14' Account='Replay101' Name='Tigger setup on 1 Minute (Target Profit Trade)' Exchange=Default Price=1884.5 Quantity=3 Market position=Short Commission=0 Order='58ab612511634435940ad57ed112cc22' Time='5/22/2014 9:30:42 AM'
        
        PROFIT TRADE ENTERED
        
        Time: 5/22/2014 9:31:00 AM OnPositionUpdate: Instrument='ES 06-14' Account='Replay101' Avg price=1884.5 Quantity=3 Market position=Short
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Runner Trade)' State=PendingSubmit Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='53472a31a06746daa919fc0c7f73b4ac' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Runner Trade)' State=Accepted Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='53472a31a06746daa919fc0c7f73b4ac' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Runner Trade)' State=Working Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='53472a31a06746daa919fc0c7f73b4ac' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=PendingChange Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=Accepted Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:31:00 AM OnOrderUpdate: Order='Replay101' Name='Tigger setup on 1 Minute (Runner Trade)' State=Filled Instrument='ES 06-14' Action=SellShort Limit price=0 Stop price=0 Quantity=2 Type=Market Tif=Gtc OverFill=False Oco='' Filled=2 Fill price=1884.5 Token='53472a31a06746daa919fc0c7f73b4ac' Gtd='1/1/0001 12:00:00 AM'
        
        Time: 5/22/2014 9:31:00 AM OnExecution: Execution=Instrument='ES 06-14' Account='Replay101' Name='Tigger setup on 1 Minute (Runner Trade)' Exchange=Default Price=1884.5 Quantity=2 Market position=Short Commission=0 Order='53472a31a06746daa919fc0c7f73b4ac' Time='5/22/2014 9:30:42 AM'
        
        RUNNER TRADE ENTERED
        
        Time: 5/22/2014 9:31:00 AM OnPositionUpdate: Instrument='ES 06-14' Account='Replay101' Avg price=1884.5 Quantity=5 Market position=Short
        
        PROFIT TRADE REACHED AND EXECUTED: STOPLOSS IS CANCELLED?
        
        Time: 5/22/2014 9:36:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=PendingCancel Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:36:00 AM OnOrderUpdate: Order='Replay101' Name='Stop loss' State=Cancelled Instrument='ES 06-14' Action=BuyToCover Limit price=0 Stop price=1887.5 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=0 Fill price=0 Token='664ced7597944862a7621df0d5d67a29' Gtd='1/1/0001 12:00:00 AM'
        Time: 5/22/2014 9:36:00 AM OnOrderUpdate: Order='Replay101' Name='Profit target' State=Filled Instrument='ES 06-14' Action=BuyToCover Limit price=1883.75 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='ce808aff19e84bb0ab37c7612b6ed64f-221' Filled=3 Fill price=1883.75 Token='84bfbc64efb04b77af639961d0e42217' Gtd='1/1/0001 12:00:00 AM'
        
        Time: 5/22/2014 9:36:00 AM OnExecution: Execution=Instrument='ES 06-14' Account='Replay101' Name='Profit target' Exchange=Default Price=1883.75 Quantity=3 Market position=Long Commission=0 Order='84bfbc64efb04b77af639961d0e42217' Time='5/22/2014 9:35:10 AM'
        
        RESETTING STOP LOSS TO BREAK EVEN HERE IN OnExecution() after 'Profit target' is filled -- BUT NO ORDER CHANGE SHOWS UP?
        
        Time: 5/22/2014 9:36:00 AM OnPositionUpdate: Instrument='ES 06-14' Account='Replay101' Avg price=1884.5 Quantity=2 Market position=Short
        Notice that 3 contracts were correctly covered and that 2 contracts remained afterwards (for the "runner" trade). However, OnOrderUpdate shows "Name='Stop loss' State=Cancelled" ... does this mean that the stop was cancelled with the profit trade was executed?

        How should I structure this to work correctly?

        Comment


          #5
          risingfire, the Set's are really meant as convenience methods and as such do not provide IOrder returns or ways to define custom names. They would always be named StopLoss or ProfitTarget, you can just tie them to a entry signal in the managed approach. Provided you scaled in for your scale out first.

          Are you looking to provide a dynamic aspect to your stops? So for example a trailing effect where you would call the stop to adjust on bars updates as the trade progresses? If not then I would just define them all in the Initialize() with your .Ticks calculation mode.

          You also want to get familiar with the powerful TraceOrders debugging feature we offer for strategies - http://www.ninjatrader.com/support/h...raceorders.htm It will print very helpful debug info to the NT output window.

          If you seek more detailed IOrder based info about your orders and ways to use the advanced non bar update based event driven methods effectively then, then I would consider switching to the the Exit() methods.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Thank you, Bertrand. TraceOrders was immensely helpful! I do have dynamic stops, so have opted to use the Exit() methods. It is all working perfectly now with multiple targets and stops. Many thanks to you and Paul for your help.

            Comment


              #7
              We're glad to hear that update risingfire
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Hi Bertrand,

                I just ran into an interesting situation that I do not understand. After one of the profit-target trades, the number of remaining contracts was not correct. From TraceOrders in OnExecution():

                NEW ORDER EXECUTED: Execution='a3f889c13bc349769d88624fb5027810' Instrument='ES 06-14' Account='Replay101' Name='Tigger setup on 1 Minute' Exchange=Default Price=1887.5 Quantity=4 Market position=Long Commission=0 Order='cb53cc3f78964a05a9898b780109350d' Time='5/22/2014 9:45:23 AM', order: Order='cb53cc3f78964a05a9898b780109350d/Replay101' Name='Tigger setup on 1 Minute' State=PartFilled Instrument='ES 06-14' Action=Buy Limit price=0 Stop price=0 Quantity=5 Type=Market Tif=Gtc OverFill=False Oco='' Filled=4 Fill price=1887.5 Token='cb53cc3f78964a05a9898b780109350d' Gtd='1/1/0001 12:00:00 AM'
                State=PartFilled, Total quanity so far: 4

                5/22/2014 9:45:23 AM Entered internal PlaceOrder() method at 5/22/2014 9:45:23 AM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=4 LimitPrice=0 StopPrice=1884.50 SignalName='Stop Loss' FromEntrySignal='Tigger setup on 1 Minute'
                5/22/2014 9:45:23 AM Entered internal PlaceOrder() method at 5/22/2014 9:45:23 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=2 LimitPrice=1888.25 StopPrice=0 SignalName='Profit Target' FromEntrySignal='Tigger setup on 1 Minute'

                NEW ORDER EXECUTED: Execution='3933e06924b641d0931e1ae555a86709' Instrument='ES 06-14' Account='Replay101' Name='Tigger setup on 1 Minute' Exchange=Default Price=1887.75 Quantity=1 Market position=Long Commission=0 Order='cb53cc3f78964a05a9898b780109350d' Time='5/22/2014 9:45:23 AM', order: Order='cb53cc3f78964a05a9898b780109350d/Replay101' Name='Tigger setup on 1 Minute' State=Filled Instrument='ES 06-14' Action=Buy Limit price=0 Stop price=0 Quantity=5 Type=Market Tif=Gtc OverFill=False Oco='' Filled=5 Fill price=1887.55 Token='cb53cc3f78964a05a9898b780109350d' Gtd='1/1/0001 12:00:00 AM'
                State=Filled, Total quanity so far: 5

                I now set a stop on all 5 contracts, and a limit order on 3:

                5/22/2014 9:45:23 AM Entered internal PlaceOrder() method at 5/22/2014 9:45:23 AM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=5 LimitPrice=0 StopPrice=1884.50 SignalName='Stop Loss' FromEntrySignal='Tigger setup on 1 Minute'
                5/22/2014 9:45:23 AM Amended matching order: Action=Sell OrderType=Stop Quantity=5 LimitPrice=0 StopPrice=1884.50 SignalName=Stop Loss' FromEntrySignal='Tigger setup on 1 Minute'
                5/22/2014 9:45:23 AM Entered internal PlaceOrder() method at 5/22/2014 9:45:23 AM: BarsInProgress=0 Action=Sell OrderType=Limit Quantity=3 LimitPrice=1888.25 StopPrice=0 SignalName='Profit Target' FromEntrySignal='Tigger setup on 1 Minute'
                5/22/2014 9:45:23 AM Amended matching order: Action=Sell OrderType=Limit Quantity=3 LimitPrice=1888.25 StopPrice=0 SignalName=Profit Target' FromEntrySignal='Tigger setup on 1 Minute'

                The target is reached and filled for 3 contracts:

                TARGET execution recevied
                targetOrder: Order='56bffbac75b74573a5fcc2dc9e7983d0/Replay101' Name='Profit Target' State=PartFilled Instrument='ES 06-14' Action=Sell Limit price=1888.25 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=1888.25 Token='56bffbac75b74573a5fcc2dc9e7983d0' Gtd='1/1/0001 12:00:00 AM'

                I now want to reset the stop order on the outstanding 2 contracts. I thought that I would be able to get the outstanding remaining contracts by querying Position.Quantity. However, Position.Quantity == 4 for some reason, not 2.

                RESETTING STOP TO BREAK EVEN: Price: 1887.55, QTY=4
                5/22/2014 9:47:05 AM Entered internal PlaceOrder() method at 5/22/2014 9:47:05 AM: BarsInProgress=0 Action=Sell OrderType=Stop Quantity=4 LimitPrice=0 StopPrice=1887.50 SignalName='Profit Stop' FromEntrySignal='Tigger setup on 1 Minute'

                Is Position.Quantity guaranteed to have the correct updated number of remaining contracts, or is there some other way I should be determining this? I noticed that targetOrder filled with a State == PartFilled, even though it did fill all 3 contracts at once. So... I'm just not sure how to understand this fill and the discrepancy with the number of contracts that should be remaining after the fill (2) rather than the number received from Position.Quantity (4).

                Comment


                  #9
                  Hi risingfire, I'm sorry but not fully following your train of thought here -

                  targetOrder: Order='56bffbac75b74573a5fcc2dc9e7983d0/Replay101' Name='Profit Target' State=PartFilled Instrument='ES 06-14' Action=Sell Limit price=1888.25 Stop price=0 Quantity=3 Type=Limit Tif=Gtc OverFill=False Oco='' Filled=1 Fill price=1888.25 Token='56bffbac75b74573a5fcc2dc9e7983d0' Gtd='1/1/0001 12:00:00 AM'

                  That target is in PartFilled state as you total qty was 3 but only 1 filled per this trace.
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    Oh, such a simple thing. I was so focused on Quantity that I overlooked the actual Fill. Yes, that was the issue. So now I'm just waiting until the fill completes and then move the stop... all is well once again. Thanks, Bertrand.

                    Comment


                      #11
                      I note that the initial question posted by the OP in post #1 was never really answered with a definitive yes or no.

                      Can someone summarize the yes/no answer to the question in post #1?

                      Comment


                        #12
                        Originally posted by bltdavid View Post
                        I note that the initial question posted by the OP in post #1 was never really answered with a definitive yes or no.

                        Can someone summarize the yes/no answer to the question in post #1?
                        Yes, I found that when using the managed order methods (ExitLongLimit(), ExitLongStop(), etc.) that NT automatically cancels associated orders when the associated limit or stop order is filled.

                        Here is an example I just ran demonstrating this using my debug output:

                        I enter a short position with 5 contracts (EnterShort() or EnterShortLimit(), etc.) and after it fills I immediately place both a target limit order and stop loss order (ExitShortLimit(), ExitLongStop()).

                        TraceOrders shows them being placed:

                        7/1/2014 1:08:57 PM Entered internal PlaceOrder() method at 7/1/2014 1:08:57 PM: BarsInProgress=0 Action=BuyToCover OrderType=Limit Quantity=5 LimitPrice=105.08 StopPrice=0 SignalName='Profit Target 0-779' FromEntrySignal='Tigger setup on 3 Minute'
                        7/1/2014 1:08:57 PM Entered internal PlaceOrder() method at 7/1/2014 1:08:57 PM: BarsInProgress=0 Action=BuyToCover OrderType=Stop Quantity=5 LimitPrice=0 StopPrice=105.23 SignalName='Stop Loss' FromEntrySignal='Tigger setup on 3 Minute'

                        The price action then hits my target and fills the 5 contracts. Once all 5 contracts are filled, I see this from TraceOrders:

                        7/1/2014 1:09:39 PM Cancelled pending exit order, since associated position is closed: Order='13adb47fef724e348735f554f8b8f807/Replay101' Name='Stop Loss' State=Accepted Instrument='CL 08-14' Action=BuyToCover Limit price=0 Stop price=105.23 Quantity=5 Strategy='MTFMA Trading Strategy' Type=Stop Tif=Gtc Oco='' Filled=0 Fill price=0 Token='13adb47fef724e348735f554f8b8f807' Gtd='12/1/2099 12:00:00 AM'
                        ******************* Time: 7/1/2014 1:10:00 PM OnOrderUpdate: Order='13adb47fef724e348735f554f8b8f807/Replay101' Name='Stop Loss' State=PendingCancel Instrument='CL 08-14' Action=BuyToCover Limit price=0 Stop price=105.23 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='13adb47fef724e348735f554f8b8f807' Gtd='1/1/0001 12:00:00 AM'
                        ******************* Time: 7/1/2014 1:10:00 PM OnOrderUpdate: Order='13adb47fef724e348735f554f8b8f807/Replay101' Name='Stop Loss' State=Cancelled Instrument='CL 08-14' Action=BuyToCover Limit price=0 Stop price=105.23 Quantity=5 Type=Stop Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='13adb47fef724e348735f554f8b8f807' Gtd='1/1/0001 12:00:00 AM'

                        NT automatically cancelled the pending Stop order since, as their Trace output shows, "associated position is closed".

                        Please note that the reason I was *not* seeing the behavior (and was the reason for me posting this question) was because I needed to ensure that the signalName in ExitShortLimit() was unique in the strategy session.

                        ExitShortLimit(int quantity, double limitPrice, string signalName, string fromEntrySignal)

                        I had just been using the same signal name ("Profit Target"). I changed this to append a simple counter + the CurrentBar in order to ensure that it would always be unique (SignalName='Profit Target 0-779' in the above example where 0 was the counter and 779 was the CurrentBar).

                        This unique signalName was the "glue" to tell NT how to tie the orders together.

                        Note: I just noticed that I am not ensuring that the signalName for the stop order is also unique (ExitShortStop()). Oddly, it seems to be working, but I imagine that this should also be unique.

                        Comment


                          #13
                          I name all my long orders as "L" + CurrentBars[0] and short orders as "S" + CurrentBars[0], so my entry names have been unique as well.

                          Here's an idea that might help you.

                          Inside OnExecution, when entering stop and profit target orders, I append "stp" or "tgt" to the above name, which essentially makes the stop and target order names unique, too.

                          Thus, for example, my order names might be,

                          "S234" <--- short order entered at bar 234 in OnBarUpdate
                          "S234stp" <-- stop loss order for "S234" entered in OnExecution
                          "S234tgt" <-- profit target order entered for "S234" in OnExecution

                          I've always seen excellent order management by NinjaTrader using their managed approach.

                          Good discussion, thanks.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by cirzonorkecv, Yesterday, 11:52 PM
                          0 responses
                          6 views
                          0 likes
                          Last Post cirzonorkecv  
                          Started by rickyblah12, Yesterday, 01:01 PM
                          1 response
                          14 views
                          0 likes
                          Last Post Erwin Beckers  
                          Started by dadarara, Yesterday, 12:18 PM
                          0 responses
                          8 views
                          0 likes
                          Last Post dadarara  
                          Started by joemiller, Yesterday, 07:33 AM
                          2 responses
                          13 views
                          0 likes
                          Last Post joemiller  
                          Started by TheGameOfProbabilities, 07-18-2019, 06:56 AM
                          7 responses
                          38 views
                          0 likes
                          Last Post DaveS
                          by DaveS
                           
                          Working...
                          X