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 Targets/Stops

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

    Multiple Targets/Stops

    If i want to run bracket orders that go out via onexecutionupdate but I want to sell half of the position at one target and the other half at at another price target but both have the same stop do I need to make 2 different order entries and assign a different stop to each one.

    For example,

    Let's say my default quantity when starting the strategy is 2 contracts.

    If I'm currently using a gtc bracket like this:

    ExitShortStopMarket(0, true, execution.Quantity, stop, "BEAR STOP", "BEAR TRIGGER");
    ExitLongMIT(0, true, execution.Quantity, target, "BULL TARGET", "BULL TRIGGER");

    Do I need to setup 2 seperate entries with their own exits?

    Like this:


    if(trigger conditions met)

    EnterLong(Quantity, "BULL TRIGGER 1");
    EnterLong(Quantity, "BULL TRIGGER 2");


    ExitLongMIT(0, true, execution.Quantity, target, "BULL TARGET 1", "BULL TRIGGER 2");

    ExitLongMIT(0, true, execution.Quantity, target, "BULL TARGET 2", "BULL TRIGGER 2");

    or can i just create a var that is assigned half of the position side and send 2 stops out with the same name each for 1 contract like this:

    int halfExecution = (execution.Quantity / 2);

    ExitLongMIT(0, true, halfExecution, target, "BULL TARGET", "BULL TRIGGER");

    ExitLongMIT(0, true, halfExecution, target2, "BULL TARGET2", "BULL TRIGGER");


    ************

    So in other words, can I have 2 separate exits for the same entry trigger?
    Last edited by gordongekko; 03-05-2018, 12:54 PM.

    #2
    Hello gordongekko,

    While it is allowed to exit a specific quantity, it is recommended that separate entries are used with different signal names to prevent any confusion with order trade matching in the performance.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      How do i submit 2 seperate market orders to go long/short? I tried this:

      EnterLong(Quantity, "BULL TRIGGER 1");
      EnterLong(Quantity, "BULL TRIGGER 2");

      And the 2nd order is not being accepted because I'm already long at the time even when it gets resubmitted. Can I send a market order for 2 contracts and then send out 2 different stops for half of the execution amount each after the fill? Also how would you recommend doing this?
      Last edited by gordongekko; 03-05-2018, 04:05 PM.

      Comment


        #4
        Hello gordongekko,

        I suspect that you are not setting EntriesPerDirection appropriately so it is then limiting your entries. Please set EntriesPerDirection to Unique Entries or set the value for All Entries to represent the maximum number of entries you want to have your strategy execute.

        EntriesPerDirection property is outlined here: https://ninjatrader.com/support/help...rdirection.htm

        The property can also be set when you enable the strategy - https://ninjatrader.com/support/help...tegyProperties

        The following code can be used to test this as well:

        Code:
        protected override void OnBarUpdate()
        {
        	if(State == State.Historical)
        		return;
        	
        	EnterLong(1, "Signal 1"); 
        	EnterLong(1, "Signal 2"); 
        	
        	if(Position.MarketPosition == MarketPosition.Long)
        		ExitLong();
        }
        Please let me know if I can be of further assistance.
        JimNinjaTrader Customer Service

        Comment


          #5
          Is there a way to check which trigger name is long or short at any given time? I don't want to be moving a trailing stop for a position that doesn't exist. For example, instead of checking:

          if(Position.MarketPosition == MarketPosition.Long)

          Can I check for if "BULL TRIGGER 2"

          currently has a position on every time onbarupdate is called so I can adjust the trailing stop for position 2 only if a position is on. I'm not sure what will happen if I send in a stop change for a position that isn't there.
          Last edited by gordongekko; 03-05-2018, 05:11 PM.

          Comment


            #6
            Hello gordongekko,

            The Position object refers to the overall position that the strategy has. If you want to focus your positions to specific orders, I would recommend looking into Advanced Order Handling and to use Order objects to track your orders and related positions. Order objects can hold signal names with the Name property as well as fromEntrySignals.

            For example:
            1. Submit entry order in OnBarUpdate() when Order object is null and conditions allow entry
            2. Assign entry order to Order object in OnOrderUpdate()
            3. Submit Profit Target and Stop Loss as Exit methods in OnExecutionUpdate()
            4. Set Order objects to null when filled in OnExecutionUpdate() and set them to null if they are cancelled in OnOrderUpdate().


            I highly recommend reviewing the SampleOnOrderUpdate strategy and associated documentation to see how this can be implemented.

            Please keep in mind the Internal Order Handling Rules of the Managed Approach that will prevent long and short entries on the same bar and short entries while in a long position will reverse your position. Some options for a strategy that can go long and short at the same time would be to add logic that controls Long/Short entries and to enable one instance configured for Long and another instance configured for Short. Another option will be to use the Unmanaged Approach.

            Internal order handling - https://ninjatrader.com/support/help...antedPositions

            Please let us know if you have any questions.
            Last edited by NinjaTrader_Jim; 03-06-2018, 08:55 AM.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by LawrenHom, Today, 10:45 PM
            0 responses
            3 views
            0 likes
            Last Post LawrenHom  
            Started by love2code2trade, Yesterday, 01:45 PM
            4 responses
            28 views
            0 likes
            Last Post love2code2trade  
            Started by funk10101, Today, 09:43 PM
            0 responses
            7 views
            0 likes
            Last Post funk10101  
            Started by pkefal, 04-11-2024, 07:39 AM
            11 responses
            37 views
            0 likes
            Last Post jeronymite  
            Started by bill2023, Yesterday, 08:51 AM
            8 responses
            44 views
            0 likes
            Last Post bill2023  
            Working...
            X