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

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
    Chris L.NinjaTrader Customer Service

    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.
        Chris L.NinjaTrader Customer Service

        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.
            Chris L.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by bsbisme, Yesterday, 02:08 PM
            1 response
            15 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by prdecast, Today, 06:07 AM
            0 responses
            3 views
            0 likes
            Last Post prdecast  
            Started by i019945nj, 12-14-2023, 06:41 AM
            3 responses
            60 views
            0 likes
            Last Post i019945nj  
            Started by TraderBCL, Today, 04:38 AM
            2 responses
            18 views
            0 likes
            Last Post TraderBCL  
            Started by martin70, 03-24-2023, 04:58 AM
            14 responses
            106 views
            0 likes
            Last Post martin70  
            Working...
            X