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

Change StopLoss Position Size if I take manual target

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

    Change StopLoss Position Size if I take manual target

    I have a hardcoded stoploss ("Set" method) however if I manually take profit the stoploss doesnt update.

    Example: I'm short 2 contracts, take one off for profit but stoploss still shows contracts. ..... How do I get it to change to 1 contract (or however many I have on)?

    Thank you!

    #2
    Hello elcowen,

    Thanks for your post.

    If by manually take profit you mean that you placed an order outside of the strategy, then there would be no means to change the strategy position as it will maintain what it knows it placed, regardless of any external influences. The recommendation would be to stop/close the strategy because if/when the stop loss is hit (using your 2 short contract example), the strategy would issue 1 buy order which would close the short order (in your account) but then would issue a 2nd buy order to close the other virtual position which then leaves you with1 live long contract and the strategy position would be flat meaning no protective orders.

    Strategies will maintain the virtual strategy positions and if they are out of sync with their account position then you will end up with unexpected positions because the strategy continues to function as you designed. For example, continuing the example with the strategy position flat and the account position of 1 long if the next strategy order was to place an order for 2 long, the strategy position would be 2 long but the account position would not be 3 long.

    If it is the strategy that is taking one off for profit then what you would need to do is create two separate entry orders with two different signal names and create two different profit targets/stops with the same entry signal names to tie them together.


    .
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      I'm not blindly running the algo. I'm turning it on and off (rather than manually entering trade). So I need to update the current position (live position) if I close half the position.

      Can this be done using OnExecution? Say I close half the position, then I want the stoploss to recognize that only half the position is left and change accordingly.

      Comment


        #4
        Maybe thats not clear... how do I get StopLoss to recognize the current position size? Maybe,..SetStopLoss(CurrentPosition,High[1])?? Thx

        Comment


          #5
          Hello elcowen,

          Thanks for your reply.

          I'm not understanding. Can you clarify exactly how you are using the strategy? Are you manually (external to) the strategy closing positions?

          Can you provide a step by step sequencing of what you are doing to help clarify?

          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Sure.

            Example:

            Enter Short 2 contracts & stoploss == 2 contracts....then I manually take a profit target on 1 contract.

            Now I'm short 1 contract & stoploss == 2 contracts



            How do I get the stoploss to reflect my current market position of 1 contract??

            Comment


              #7
              Hello elcowen,

              Thanks for your reply.

              The only option here would be to change your strategy to the Unmanaged Approach and use the Position.Account as a means to trigger a change to the (stop) order and use ChangeOrder().to accomplish that change.

              References:


              Paul H.NinjaTrader Customer Service

              Comment


                #8
                To summarize: I'm need to change the StopLoss Qty to reflect my current position quantity...after I've manually taken Profit Targets.


                I have the unmanaged approach working. However the ChangeOrder() isnt. I've put the code in the BarUpdate() section and tried in OnExecutionUpdate() none of which works. What am I doing wrong??

                if (stopOrder != null && stopOrder.StopPrice < Position.AveragePrice)
                ChangeOrder(stopOrder, Position.Quantity, Position.AveragePrice + 20 * TickSize, Math.Min(Lows[1][1], Lows[1][2]) - 1 * TickSize);


                Thank you

                Comment


                  #9
                  Hello elcowen,

                  Thanks for your reply.

                  I've attached a working example you can test in real-time using your sim101 account or playback with market replay data.

                  It will place an order quantity of 2 for the entry and generate stop/profit for 2. When you manually close 1 contract the OnAcctPositionUpdate() is triggered where the position is then checked and the stop/profit are changed.

                  UnmanagedExampleforelcowen.zip
                  Last edited by NinjaTrader_PaulH; 11-13-2020, 03:18 PM. Reason: Updated example.
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10

                    Last issue is when I exit last contract my stop order is still open. Is there a way to cancel all orders once I exit last position?


                    Here's what I tried....

                    Click image for larger version

Name:	unmanaged.11.12.20.PNG
Views:	219
Size:	60.9 KB
ID:	1127294
                    Thx

                    Comment


                      #11
                      Hello elcowen,

                      Thanks for your reply.

                      In the example we provided, after the entry order for 2 contracts fills, when you sell 1 contract manually, the profit and stop orders are reduced to one. If the price then hits either order the position is closed and the un hit order is canceled.

                      Can you retest the example as we provided and advise if you see the same?




                      Paul H.NinjaTrader Customer Service

                      Comment


                        #12

                        I think the problem is when I take the second profit target manually the profit target and stop loss remain open.

                        Will I need to hit 'Close' for the last target rather than submitting a limit order (its ok if I do, just want to make sure).

                        Thx



                        Click image for larger version

Name:	unmanaged.11.12.20.ES flat but open.PNG
Views:	206
Size:	54.6 KB
ID:	1127361





                        Comment


                          #13
                          Hello elcowen,

                          Thanks for your reply.

                          We've updated the example in post #9, please re-download and replace the example previously provided.

                          Paul H.NinjaTrader Customer Service

                          Comment


                            #14
                            Perfect! You're the man and deserve a raise! Haha Thank you!!!!!!

                            Comment

                            Latest Posts

                            Collapse

                            Topics Statistics Last Post
                            Started by ZeroKuhl, Yesterday, 04:31 PM
                            8 responses
                            42 views
                            0 likes
                            Last Post ZeroKuhl  
                            Started by reynoldsn, Today, 07:04 PM
                            0 responses
                            6 views
                            0 likes
                            Last Post reynoldsn  
                            Started by puapwr, Today, 06:09 PM
                            0 responses
                            4 views
                            0 likes
                            Last Post puapwr
                            by puapwr
                             
                            Started by franciscog21, Today, 05:27 PM
                            0 responses
                            10 views
                            0 likes
                            Last Post franciscog21  
                            Started by hdge4u, 04-29-2024, 12:23 PM
                            5 responses
                            28 views
                            0 likes
                            Last Post MisterTee  
                            Working...
                            X