Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Question on multiple exits [OnExecution(), OnOrderUpdate()]

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

    Question on multiple exits [OnExecution(), OnOrderUpdate()]

    Hello everyone!
    I'm coding a strategy base on a single entry with (let's say) 3 lots with 3 exits based on objective levels (Position.AvgPrice + target1*TickSize), same for stop level.

    All my positions are related to Position.Quantity, so let's say I'm long 3, I place an exit for 1 (target) and 3(stop), if I have 2 lots running (first has been executed) place 1 esit for 1 lot (target) and 2 (stop).....

    Now I would like to understand how to manage OnExecution and OnOrderUpdate methods, better ...do I need to use methods for each position? or do I need to use just one at the beginning?
    I'm a bit confusing, thanks for your suggestions,

    Regrads
    MB

    Below a piece of code as example:
    entry rules are defined within OnBarUpdate()

    Code:
    if (Position.MarketPosition == MarketPosition.Long){//Long position
    					if (Position.Quantity == ctr)
    					{
    					
    						ExitLongLimit(ctr/3, (Position.AvgPrice + target1*TickSize), "1st Exit", "");
    						ExitLongStop(ctr, (Position.AvgPrice - stop*TickSize), "1stStop", "");
    					}
    					else if (Position.Quantity == (ctr/3)*2)
    					
    					{
    						ExitLongLimit(ctr/3, (Position.AvgPrice + target2*TickSize), "2nd Exit", "");
    					    ExitLongStop(Position.Quantity , (Position.AvgPrice - secondstop*TickSize), "2ndStop", "");
    						
    					}
    					else if (Position.Quantity == (ctr/3))
    						ExitLongStop(Position.Quantity , (Position.AvgPrice + thirdstop*TickSize), "LastStop", "");
    				}else{
    					// Short					
    					if (Position.Quantity == ctr)
    					{
    						ExitShortLimit(ctr/3, (Position.AvgPrice - target1*TickSize), "1st Exit", "");
    						ExitShortStop(Position.Quantity , (Position.AvgPrice + stop*TickSize), "1stStop", "");
    					}
    					else if (Position.Quantity == (ctr/3)*2)
    						
    					{
    						ExitShortLimit(ctr/3, (Position.AvgPrice - target2*TickSize), "2nd Exit", "");
    						ExitShortStop(Position.Quantity , (Position.AvgPrice + secondstop*TickSize), "2ndStop", "");
    					}
    					else if (Position.Quantity == (ctr/3))
    							ExitShortStop(Position.Quantity , (Position.AvgPrice - thirdstop*TickSize), "LastStop", "");

    #2
    MrBaffalo,

    Not sure I understand what you are asking exactly. To manage an order in OnExecution you need to use IOrder objects for all your orders. This way you can distinguish which order is triggering the event.

    Also, remember in terms of scaling out you will need to scale in with 3 entry orders first.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks Josh for your quick suggestion.
      Now I enter a single order:
      Code:
      	if (CrossAbove(....., ....., 1)&&(CCI(Close, cciper)[1] > 0))
      			{
      				EnterLong(ctr);
      			}
      			
      			if (CrossBelow(....,...., 1)&&(CCI(Close, cciper)[1] < 0))
      			{
      				EnterShort(ctr);
      			}
      How do I scale in three entries on the same trigger?

      Hope it helps you to understand the logic of my strategy.
      Anyway how do I manage the exits with IOrder objects?

      Thanks
      MB

      Comment


        #4
        MrBaffalo,

        Call EnterLong 3 times giving them separate signal names each. Then when you run your strategy ensure you have EntriesPerDirection greater than or equal to 3.

        Please review the reference sample on IOrders here: http://www.ninjatrader-support2.com/...ead.php?t=7499
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          OK, this is a trick, I appreciate that, but still do not understand why do I need to manage 3 entries on a single trigger...it's non linear...real life I could be executed with a partial fill (2 entry order gets filled and one not) that's doesn't sound a good way to manage a code.
          I learned to be as linear and clean as possible, I think this is not the right way.
          Anyway I think and I appreciate if you NT Guys could make some more fitting sample on questions, it would be a time saving for everyone.

          MB

          Comment


            #6
            MrBaffalo,

            We are constantly expanding the educational resources, but we cannot create a reference sample for every scenario customers want.

            You need to submit 3 entries for proper signal tracking. This is a requirement to scale-out at the moment.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              Will do,
              thanks
              MB

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              576 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              334 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              553 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              551 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X