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

Automatically close position on breach of unrealized loss threshold

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

    Automatically close position on breach of unrealized loss threshold

    Hello
    I am looking for help with strategy to programmatically manage max loss .

    This is the use case.
    If I start a position, and the position goes underwater below a preset threshold, I want the program to automatically close the position. Example I take 2 ES longs, and if it goes below $1000 in unrealized loss, I need the program to automatically liquidate the position.

    So the program should keep track of current position and its P&L using OnBarUpdate(), I would imagine

    The Ninja brokerage is not able to enforce this. They can prevent new position once loss is booked and if loss is more than pre set limit.But they can not auto liquidate live position.

    I only trade ES. I have disabled trading in any other instrument. So I will only have just ES at any time.

    This will help me avoid'deer in headlight' scenario. I already have enabled max loss with brokerage. Once the limit is reached, brokerage will not let me open new positions.

    so combined with this program, I can be assured that my daily loss will not exceed max set limit.


    Any pointers on how this can be achieved?

    #2
    Hello myrx100,
    Thanks for your post.

    Check out the following forum thread with an example of how to program a 'daily stop loss' strategy. This should be perfect for what you are trying to do.

    Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatrader
    Josh G.NinjaTrader Customer Service

    Comment


      #3
      Thanks for the program.
      I could not figure out how the program works.
      I noticed by default the PNL=100.
      I deployed this strategy on SIM account using simulated data feed.
      Then I used the DOM to enter an order. But the program is not detecting my position going below 100 loss and did not liquidate position.

      Would the strategy work only when you enter a position through the strategy?

      Comment


        #4
        Would the strategy work only when you enter a position through the strategy?
        You are correct.

        NinjaScript Strategies are not able to see trades that are placed manually or from another instance of a strategy. These have their own internal position and are only able to see orders placed through the strategy.
        Josh G.NinjaTrader Customer Service

        Comment


          #5
          In that case this program does not address the original use case I posted.

          The requirement I have is to grammatically monitor daily P&L for realized and unrealized position and close out any active position if daily P&L exceeds a pre set stop loss.

          This is a great account protection measure. Too bad there is a no way to implement this

          Comment


            #6
            I meant 'programmatically' not 'grammatically" lol

            Comment


              #7
              This is not possible in NT7 outside of the strategy option I provided.
              Josh G.NinjaTrader Customer Service

              Comment


                #8
                Is it possible in Ninja 8?

                Comment


                  #9
                  It would be possible to accomplish something like this in NT8 by using the Addon framework to "listen" for account events like a fill, and then execute other logic. This help guide page has a great example of listening for account updates. Although the page says this is for an "Addon", you could also use this inside of an indicator or strategy.



                  I think it is important to note that there is a divide between what a strategy does, and what you want. The difference here is that you're doing all the subscribing, choosing accounts, etc. yourself, and in the case of a strategy all this stuff is handled for you. What I believe that you want is something that acts like a tool similar to how a superDOM works which is not how strategies are intended to work. A strategy is specifically meant to be isolated so when you collect its performance, its for that script, so you can differentiate that data.

                  So, if you want the same reporting that you would get using a manual tool like the superDOM, that is where the addon framework comes in. You're not using a strategy with the managed approach, but instead just making your own tool that behaves how you want it to. Then you are just interfacing with the standard C# objects in the platform.
                  Josh G.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by BarzTrading, Today, 07:25 AM
                  2 responses
                  12 views
                  1 like
                  Last Post BarzTrading  
                  Started by devatechnologies, 04-14-2024, 02:58 PM
                  3 responses
                  19 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by tkaboris, Today, 08:01 AM
                  0 responses
                  3 views
                  0 likes
                  Last Post tkaboris  
                  Started by EB Worx, 04-04-2023, 02:34 AM
                  7 responses
                  162 views
                  0 likes
                  Last Post VFI26
                  by VFI26
                   
                  Started by Mizzouman1, Today, 07:35 AM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X