• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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:

    https://ninjatrader.com/support/help...and_onexec.htm


    Let me know if any questions come up.
    JoshNinjaTrader 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?

        https://ninjatrader.com/support/help...a_position.htm
        JoshNinjaTrader 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
            JoshNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Zoomy55, Today, 08:20 AM
            2 responses
            15 views
            0 likes
            Last Post Zoomy55
            by Zoomy55
             
            Started by SOFI777, Today, 08:02 AM
            1 response
            2 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by U0000999, Today, 08:12 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_PatrickG  
            Started by U0000999, Today, 08:07 AM
            1 response
            3 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Started by SOFI777, Today, 07:50 AM
            1 response
            7 views
            0 likes
            Last Post NinjaTrader_ChrisL  
            Working...
            X