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 HTrader, Today, 09:12 PM
            2 responses
            6 views
            0 likes
            Last Post HTrader
            by HTrader
             
            Started by firstlanetech, Today, 08:56 PM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by robbersdog, Today, 07:55 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by SuperDude123, Today, 09:08 AM
            2 responses
            39 views
            0 likes
            Last Post SuperDude123  
            Started by trader3000a, Today, 08:01 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Working...
            X