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

Multiple Entries with SET methods to exit (OCO)

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

    Multiple Entries with SET methods to exit (OCO)

    Hi,
    Can you please explain how the strategy works with multiple entries with different entry name with setprofittarget and setstoploss for exits for below two cases? It will be great if you can answer all the questions, it will help me in my strategy design and helps in understanding order execution. I went through the HELP and understand most of it related to SET methods. I am more interested in Case1 as I will have more control to modify Profit Target (PT). i have not started implementing entry and exits in my strategy(to go live) as i have not completely understand the process.

    I have used ES price for examples and used below long limit order for entry
    EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

    Case1: current market is trading @ 1390 and executed below two entry methods at same price
    Entry 1: EnterLongLimit(0, true,1,1389, “entry1”)
    Entry 2: EnterLongLimit(0, true,1,1389, “entry2”)
    SetProfitTarget(“entry1”, CalculationMode.Ticks, 4)
    SetStopLoss(“entry1”, CalculationMode.Ticks, 4,false)
    SetProfitTarget(“entry2”, CalculationMode.Ticks, 4)
    SetStopLoss(“entry2”, CalculationMode.Ticks, 4,false)
    If entry1 gets filled and market moves 5 ticks in favor,
    will the profit target for entry1 gets filled and stop loss for entry1 gets cancelled (Entry2 limit buy order is still in the exchange, not yet filled)?
    What will happen to entry2?

    When the market comes below entry2 level after trading above entry1 PT(assuming entry1 exited with PT) will it get filled with entry2 price and sends PT and Stoploss orders for entry2?

    If entry1 and 2 gets filled at the same time and sends exit orders for PT and Stoploss,
    can I update the PT for one of the entries by resetting the profit target with fromEntrySignal SetProfitTarget(“entry1”, CalculationMode.Ticks, 24)?

    Case2: current market is trading @ 1390 and executed below entry method along with SET methods
    Entry 3: EnterLongLimit(0, true,100,1389, “entry3”)
    SetProfitTarget(“entry3”, CalculationMode.Ticks, 4)
    SetStopLoss(“entry3”, CalculationMode.Ticks, 4,false)

    If the price comes to 1389 and partially fill 10 out of 100,
    will the profit target and stop loss be set for 10 related to entry3?

    if the market moves in favor and traders above entry3 PT will the PT order gets filled and cancels stoploss order for 10 quantity?

    If there is a partial fill @ entry3 profit target (4 out of 10) and market comes back to entry3 level(1389) and partially fill 20 out of 90 (remaining 100 -10), will these 20 gets added to PT and stop loss orders?

    Can this process partial fill/ exit with PT or complete fill with PT or Stop loss continues till entry3 quantity completely fill?

    Thanks
    gsreddy.

    #2
    Originally posted by gsreddy View Post
    If entry1 gets filled and market moves 5 ticks in favor,
    will the profit target for entry1 gets filled and stop loss for entry1 gets cancelled (Entry2 limit buy order is still in the exchange, not yet filled)?
    What will happen to entry2?
    This would depend on how quickly this occurs. If the market is moving quick enough, it's possible that the price will exceed the level you are submitting the profit target before the target has been accepted by the broker.

    For the quickest submission of your Stops and Targets, we recommend placing these in OnExecution() or OnOrderUpdate():

    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. 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 OnOrderUpdate()


    Entry 2 would not be filled unless price came back down to your original working price.


    Originally posted by gsreddy View Post
    When the market comes below entry2 level after trading above entry1 PT(assuming entry1 exited with PT) will it get filled with entry2 price and sends PT and Stoploss orders for entry2?
    Yes, this is correct.

    Originally posted by gsreddy View Post
    If entry1 and 2 gets filled at the same time and sends exit orders for PT and Stoploss,
    can I update the PT for one of the entries by resetting the profit target with fromEntrySignal SetProfitTarget(“entry1”, CalculationMode.Ticks, 24)?
    Yes, you can change the profit target dynamically under certain conditions. Please have a look at our reference sample on changing profit target and stop loss orders:



    Originally posted by gsreddy View Post
    If the price comes to 1389 and partially fill 10 out of 100,
    will the profit target and stop loss be set for 10 related to entry3?
    Yes, it would match the position quantity.

    "A strategy will either generate a target order for each partial fill of an entry order or one order for all fills."

    This means you may have 10 contracts as a target and another 90 elsewhere, depending on how you were filled.

    You can test this out by going to Tools--> Options--> Simulator tab--> check "Enforce Partial Fills". Then you can run the strategy in the Sim101 account and see how it will behave on a partial fill.


    Originally posted by gsreddy View Post
    if the market moves in favor and traders above entry3 PT will the PT order gets filled and cancels stoploss order for 10 quantity?
    Yes.

    Originally posted by gsreddy View Post
    If there is a partial fill @ entry3 profit target (4 out of 10) and market comes back to entry3 level(1389) and partially fill 20 out of 90 (remaining 100 -10), will these 20 gets added to PT and stop loss orders?
    Yes

    Originally posted by gsreddy View Post
    Can this process partial fill/ exit with PT or complete fill with PT or Stop loss continues till entry3 quantity completely fill?
    Yes, this would be the designed behavior.

    Please let me know if you have additional questions.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Hi,

      Thanks for providing all the answers. This clarifies lot of question on OCO orders and Helps me complete my design on order entry/exits.

      I just started thing of possible error handling.
      Can you please point me to any extensive discussion thread related to error handling on entry, exit orders and connection losses (Not the Ninja HELP)? Would like to know more on real time errors after go live with a completely automated strategy.

      Thanks,
      gsreddy.

      Comment


        #4
        I don't have any threads handy for you to read.

        I'd suggest submitting initial illegal orders, such as a stop above/below the current price.

        You can use the OnOrderUpdate event to capture the order state.


        Code:
        protected override void OnOrderUpdate(IOrder order)
        {
        	if (order.OrderState == OrderState.Rejected)
        	{
        		//do something
        	}
        }
        MatthewNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by timmbbo, 07-05-2023, 10:21 PM
        4 responses
        158 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by tkaboris, Today, 08:01 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by Lumbeezl, 01-11-2022, 06:50 PM
        31 responses
        817 views
        1 like
        Last Post NinjaTrader_Adrian  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        5 responses
        15 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by swestendorf, Today, 11:14 AM
        2 responses
        6 views
        0 likes
        Last Post NinjaTrader_Kimberly  
        Working...
        X