Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why quantity can not be set for ExitLongStopMarket more than Stratetgy Position?

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

    Why quantity can not be set for ExitLongStopMarket more than Stratetgy Position?

    I have 3 Long Positions and 2 orders
    But I can not set ExitLongStopMarket(barsInProgressIndex, isLiveUntilCancelled, 5, stopPrice, null, null);
    The quantity of the generated order is just 3!

    But I can do it:
    for (var i=0; i<5; i++)
    I can not set ExitLongStopMarket(barsInProgressIndex, isLiveUntilCancelled, 5, stopPrice, i.ToString(), null);
    So the result is 5 orders with 1 quantity!

    Whats the the problem? I don't have such issue with ExitLongStopLimit

    #2
    Hello, thanks for your post.

    This code is working fine on my end:

    Code:
    private bool runOnce = false;
            protected override void OnBarUpdate()
            {
                if(State == State.Historical)
                    return;
    
                if(!runOnce)
                {
                    EnterLong(5, "LongEntry");
                    ExitLongStopMarket(5, Low[0]-TickSize*10, "StopOrder", "LongEntry");
                }
            }
    Try turning on TraceOrders in State.SetDefaults. When an order is filled/ignored/rejected, info will be printed about the order. Its possible the stop market order is being ignored or rejected.

    Kind regards.

    -Chris

    Comment


      #3

      Would you check this, I placed a limit order before stopLoss. I don't want use the FromEntrySingal


      Code:
      private bool runOnce = false;  
      
      protected override void OnBarUpdate()        
      {            
         if (State == State.Historical)          
            return;            
      
         if (!runOnce) 
         {              
                  EnterLong(5, "LongEntry");                
                  EnterLongLimit(Low[0] - TickSize * 10);              
                  ExitLongStopMarket(6, Low[0] - TickSize * 20, "StopOrder", null);          
         }      
      }
      Last edited by ManTrader; 08-27-2019, 10:45 AM.

      Comment


        #4
        Hello ManTrader, thanks for your reply.

        This will not work because ExitLong... requires there to be a long position before it is submitted. You would either need to wait for the long limit order to fill by overriding and using OnExecutionUpdate or you can set a stop loss with SetStopLoss before you enter the long limit order.

        There is an example of using OnExecutionUpdate to submit protective orders here.

        Best regards.

        Comment


          #5
          So pity, I am using AdoptAccountPosition start behavior. So there is no way to put stoploss for adopted positions!

          Comment


            #6
            Hello, thanks for your reply.

            In this case, the unmanaged approach would need to be used since the set/exit orders require an entry order to work. I attached an example of using the unmanaged approach with AdoptAccountPosition as the start behavior. More info on the unmanaged approach can be found here.

            Let me know if you have any questions on this material.
            Attached Files
            Last edited by NinjaTrader_ChelseaB; 10-26-2020, 02:28 PM.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by NullPointStrategies, Today, 05:17 AM
            0 responses
            39 views
            0 likes
            Last Post NullPointStrategies  
            Started by argusthome, 03-08-2026, 10:06 AM
            0 responses
            124 views
            0 likes
            Last Post argusthome  
            Started by NabilKhattabi, 03-06-2026, 11:18 AM
            0 responses
            64 views
            0 likes
            Last Post NabilKhattabi  
            Started by Deep42, 03-06-2026, 12:28 AM
            0 responses
            41 views
            0 likes
            Last Post Deep42
            by Deep42
             
            Started by TheRealMorford, 03-05-2026, 06:15 PM
            0 responses
            46 views
            0 likes
            Last Post TheRealMorford  
            Working...
            X