Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop a strategy if profit goal reached?

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

    Stop a strategy if profit goal reached?

    What if I want my strategy to stop executing (or I could just "return" out of OnBarUpdate) if it reaches a specified profit goal? Is there a method or class or something that holds my account's realized PnL for each strategy? This value is already shown on the Strategies tab, so I assume it's available somehow within the code.

    Even better would be a way to see the whole account's Total Net Profit value in realtime - so I can shut down all strategies if a specified profit target is reached.

    Thanks!
    Bryan
    Last edited by cassb; 04-26-2008, 08:44 PM.

    #2
    Please see this reference sample: http://www.ninjatrader-support.com/v...ead.php?t=4084
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by Josh View Post
      Excellent, thank you Josh. I downloaded that and ran it in my strategy and it works great. Except... ;-) It will only accumulate PnL for the one strategy that the accumulator variable is running in.

      What if I want to know the TOTAL PnL for all instruments and strategies in a given trading period/day? I want to stop trading if ALL of my strategies/instruments running add up to a total profit/loss value. Is that possible?

      Comment


        #4
        This is not supported.
        RayNinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Ray View Post
          This is not supported.
          Bummer, ok. But this information can be calculated, obviously, because it's available on the Account Performance tab when you generate a report. How hard would it be to come up with an object or method to get this number in the next release?

          Thanks!
          Bryan

          Comment


            #6
            Will add this to our list of items for future consideration.
            RayNinjaTrader Customer Service

            Comment


              #7
              I'm trying a workaround to not being able to get a combined Total Net Profit amount for two strategies running at the same time. I combined both strategies into one so I can get a PnL value from both at the same time. But now I'm running into the same issue I had that caused me to split this strategy up in the first place:

              An Enter() method to submit an entry order at '4/25/2008 9:44:39 AM' has been ignored. Please search on the term 'Internal Order Handling Rules' in the Help Guide for detailed explanation.

              So, I want to have two stop orders at the same time in the same strategy. One is a Long Stop order and one is a Short Stop order. How can I accomplish this without triggering that error above?

              These are the two orders I'm trying to place:

              myEntryLong = EnterLongStop(0,true,1,<some value>,"Test Long");
              myEntryShort = EnterShortStop(0,true,1,<some value>,"Test Short");

              Comment


                #8
                The workaround would be to simulate the stop order and when either one triggers, submit a market entry order.
                RayNinjaTrader Customer Service

                Comment


                  #9
                  Originally posted by NinjaTrader_Ray View Post
                  The workaround would be to simulate the stop order and when either one triggers, submit a market entry order.
                  Hmmm.... I suppose I could do that for both the long and short orders, actually. I didn't think of that. I had been using stop orders because that's how I did it manually before I set up a strategy to do it for me. I didn't want to have to watch every tick to know when to open the market orders, so I put Stop orders in instead. Now that I have the strategy watching ticks for me, I guess I can go back to market orders. Sometimes it's hard to see the forest through all those trees. Thanks Ray!

                  Comment


                    #10
                    Is there a way to store variables on disk somewhere instead of in memory? Whenever I recompile and "apply" my strategy during the trading day, it resets the priorTradesCumProfit and priorTradesCount variables.

                    Comment


                      #11
                      Sure, check the reference sample section in this forum for how to read/write to disk.
                      RayNinjaTrader Customer Service

                      Comment


                        #12
                        Originally posted by NinjaTrader_Ray View Post
                        Sure, check the reference sample section in this forum for how to read/write to disk.
                        Excellent, thank you!

                        Ray, I have to tell you that you have the most comprehensive help I have ever seen for a commercial software package. Your online support through this forum is very quick and excellent. The many pages of help documentation, examples, instructional docs and code samples is fantastic. You are certainly customer-focused and your software improves with every release.

                        You can use this text in any promotional material you'd like. My hat's off to you.

                        Comment


                          #13
                          Thank you for the compliment. Wait until you see what we have planned for Help Resources next year!
                          RayNinjaTrader Customer Service

                          Comment


                            #14
                            Please don't say you're outsourcing to India! lol

                            Comment


                              #15
                              Sorry to keep this poor thread alive, but I'm still working on this idea of using Disk I/O to store my daily overall PnL value, and to stop all strategies when a daily profit/loss goal is reached.

                              With the File methods, I am able to open the file, read the current PnL from it, add/subtract a new amount, then write the file again.

                              What I'm having trouble with is determining when to open/read/write/close the file. I think I want to do this whenever a filled order is closed and I have a new Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit value. Can you tell me when this CumProfit property is updated and how/when I can capture it? OnOrderUpdate()? OnExecution()?

                              Thank you!
                              Bryan

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              673 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              379 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              111 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              577 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              582 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X