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

SetStop not updated with correct Qty

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

    SetStop not updated with correct Qty

    Hi

    I use the following command for entry and setting the stoploss :

    SetStopLoss("Long-25",CalculationMode.Price,LastDayLow,false);
    EnterLongLimit(0,true,15, Level25, "Long-25");

    We are Long and also have a stoploss at LastDayLow. all is Ok so far.

    after a certain period of time I issue a command to Scaleout of the position:
    ExitLong(Convert.ToInt32(Position.Quantity/2),"Scaleout","Long-25");

    and the command is indeed executed and now I have 8 shares Long.

    after a while the price drops to the STOPLOSS level and I have the stop triggered.
    BUT its triggered with original QTY of 15. and instead of closing the position I have 7 shares SHORT .

    What am I doing wrong?. I need the Qty of the SETSTOP to be updated correctly.
    do I need to issue SETSTOP command again for it to be updated or it should be updated automatically ?


    #2
    Hello dadarara,
    Thanks for your post.

    You will need to update SetStopLoss() to get the quantity to update the way you would like, and I suggest using OnExecutionUpdate/OnPositionUpdate/OnOrderUpdate to track the quantity you need.

    For example, using OnExecutionUpdate you could watch for the various different orders by name, and then accumulate counters based on what those conditions see.

    https://ninjatrader.com/support/help...xecutionUpdate

    In the first example from the above page, the execution.Order.Name is used to delegate logic. You could also do this but accumulate your counts based on the orders coming in. you can also see if the order was partially filled and the quantity of the fill to accumulate accurately.

    Additionally, here is a sample strategy that shows how to use OnOrderUpdate() and OnExecution() methods to submit protective orders:




    Let me know if any questions come up.
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Josh

      the thing is that I did that but its not helping

      in the OnExecutionUpdate I have the following

      if (execution.Order.Name == "Scaleout" && execution.Order.OrderState == OrderState.Filled)
      {
      if (Position.MarketPosition==MarketPosition.Long) SetStopLoss("Long-25",CalculationMode.Price,StopLossLevel,false);
      if (Position.MarketPosition==MarketPosition.Short) SetStopLoss("Short-75",CalculationMode.Price,StopLossLevel,false);

      }

      in the log I see the Oco id related to the original order with the Qty of 15.not the the updated one I send in OnExecutionUpdate


      this is the StopLoss being executed.

      Order='fd6601cb33b7497089c4155debf1fd0b/Playback101' Name='Stop loss' New state='Filled' Instrument='TSLA' Action='Buy to cover' Limit price=0 Stop price=365.99 Quantity=15 Type='Stop Market' Time in force=GTC Oco='a90846e292c64be8b38da61fd0ef7ef5' Filled=28 Fill price=366.34 Error='No error' Native error=''

      what next ?
      Last edited by dadarara; 12-05-2018, 11:30 AM.

      Comment


        #4
        dadarara,

        You will need reset SetStopLoss() before it can be used again like this, and you can only reset SetStopLoss when you are flat.

        Have you seen the following sample that demonstrates how to scale out of a position?

        Josh G.NinjaTrader Customer Service

        Comment


          #5
          so basically if i want to use the SETStop methods I will need to make multiple separate entries. knowing in advance the Qty I will want to Scaleout with.
          the other path is NOT to use the SETStop but rather the usual dedicated stop limit orders.
          Correct ?

          Comment


            #6
            dadarara,

            You are correct
            Josh G.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Mindset, 05-06-2023, 09:03 PM
            10 responses
            262 views
            0 likes
            Last Post NinjaTrader_BrandonH  
            Started by michi08, 10-05-2018, 09:31 AM
            5 responses
            741 views
            0 likes
            Last Post NinjaTrader_ChelseaB  
            Started by The_Sec, Today, 02:29 PM
            0 responses
            2 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            4 responses
            62 views
            0 likes
            Last Post aligator  
            Started by sightcareclickhere, Today, 01:55 PM
            0 responses
            1 view
            0 likes
            Last Post sightcareclickhere  
            Working...
            X