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

How to close the trade running in a strategy from the chart trader screen

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

    How to close the trade running in a strategy from the chart trader screen

    Hello: How do I exit the trade manually that was submitted by the strategy logic without disabling the strategy ? Example, Let's say profit target is 200 and last trade submitted by strategy is making 175$ but I would like to close the trade with that profit vs wait till set profit target of 200. Basically I would like to close the trade early with whatever profit or loss but continue to run the strategy. Thanks

    #2
    Hello mtamaku,

    To close a position without disabling a NinjaScript Strategy running on the same instrument and account, place an order in the opposite direction of the position.

    For example, if you are long 2, place a sell market order with a quantity of 2.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      ChelseaB will the strategy still think is has a Long Position 2, if so then its stop would create a short?

      Comment


        #4
        Hello DTSSTS,

        Yes, placing manual orders would not cause the strategy position to change. Only the account position would change. However, this would allow you to manually trade while the strategy continuous running.

        If you want the strategy position to change, the orders have to be placed by the strategy. (You could have a button that when clicked causes the strategy to place an order.)
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi, do you have a sample code or example of how to to stop or exit the trade in progress that was placed by the strategy from the chart trader screen ?
          As you suggested at the top, I placed the sell order in opposite direction but that was a separate order from the strategy, I guess for account position. Thanks

          Comment


            #6
            Hello mtamaku,

            To modify the strategy position the strategy must place the order from its code using internal ninjascript methods.

            You could have the strategy add a button and place the order on a button click.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              you mean button to close the trade that was placed by the strategy ?

              Comment


                #8
                Hello mtamaku,

                I mean a button added by the strategy that when clicked calls ExitLong() or ExitShort() or places another type of order of your choosing.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I tried that example link you attached for button but nothing is showing on the screen when I loaded the strategy.

                  Comment


                    #10
                    Hello mtamaku,

                    This is working without issue on my end.


                    Are you certain you have enabled the strategy?
                    Does the strategy show with the Enabled checkbox checked on the Strategies tab of the Control Center?
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      It is complicated to implement in my strategy even I tried with my limited C# knowledge.
                      I am just looking for something that can close the trade that was submitted by the strategy and continue with the next trade from the strategy vs disable of the strategy.

                      Comment


                        #12
                        Put your self a trail stop if you can, place it well below whatever you are currently using, just slide the Order showing on the chart up to your current price depending on the candlestick type it may stay where you moved it long enough to trigger, thus closing your trade from within the strategy

                        Comment


                          #13
                          something i discovered today, I have a Trailing Stop that i use as a back up stop, but you can actually attach that stop to an indicator after the position is entered and it will then follow the indicator, ie may a 1 period sma of the Lows or I used a bollinger band and set to a 1.5 std dev and 20 periods , when i am in a big uptrend, i can take the trailing stop that is well below my current candles and attach it to the Upper band of the Bollinger and it will trail perfect with that and not resume the ticks of the trial of the strategy

                          Also the Profit target can be used that way as well, generally if you move the profit target down closer to your current candles it will move itself back to the correct price indicator by the strategy on the very next tick. I for example attached my profit target to Prior Day High of day and exited into that area

                          Comment


                            #14
                            Hi Chelsea, I was revisiting this old post and have no problem enabling and seeing those buttons in the chart. What I did NOT manage is to close position of the currently running and enabled strategy by pressing on one of those buttons. Did I understand correctly that by loading one-by-one bar-button strategy along with my own strategy will enable me to close position in my own strategy or I need to put bar-button strategy inside my own strategy for bar-button strategy have a desired effect. Suggested trail stop could work but bar button indeed looked pretty cool. Cheers

                            Comment


                              #15
                              Hello kazbek966,

                              A NinjaScript Strategy is only able to see orders submitted by that instance of the strategy. Other running strategy instances are not able to affect any other strategies position or orders.
                              Further, a NinjaScript strategy is not able to manually submitted orders.

                              This could mean that to have orders affect the strategy position, that strategy instance needs to have the orders submitted (from a button click if you would like).

                              I have a few better examples available now.
                              I need some guidance. I need to create a script that has 3 plots that are public and they plot either a 1 or 0. But I need to create another indicator that has 3 chart buttons that sets these variables. The first indicator needs to get those values from the second indicator depending on the button clicks. Because of using
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by josh18955, 03-25-2023, 11:16 AM
                              6 responses
                              435 views
                              0 likes
                              Last Post Delerium  
                              Started by FAQtrader, Today, 03:35 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post FAQtrader  
                              Started by rocketman7, Today, 09:41 AM
                              5 responses
                              18 views
                              0 likes
                              Last Post NinjaTrader_Jesse  
                              Started by frslvr, 04-11-2024, 07:26 AM
                              9 responses
                              126 views
                              1 like
                              Last Post caryc123  
                              Started by selu72, Today, 02:01 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_Zachary  
                              Working...
                              X