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

Strategy - how to stop strategy if certain profit is reached?

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

    Strategy - how to stop strategy if certain profit is reached?

    Is there a way to turn off strategy from running if you make $50 or $100 or whatever?

    #2
    Hello MatthewLesko,

    Thank you for your note.

    It looks from the tags like you're referring to programming this into your own strategy, so I've moved this to our NinjaTrader 8 Strategy Development forum.

    I'm attaching a basic Strategy Builder example strategy that works in real time only that uses a bool to stop entries from occurring after a set PnL has been reached. It would need to be disabled and re-enabled to resume taking trades.

    We also have an example of doing this from a manually coded strategy in our help guide here:



    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Kate thanks sorry I missed this. So I'm wondering, my strategy may either profit me between $30 and $50 if I have 1 loss and then 1 win, otherwise it will profit me between $150 and $250 if I have one win.
      So I'm thinking is there a way to just have a minimum realized profit?

      Comment


        #4
        Maybe I have a double type input/variable that is MinimumProfit and if cumulative realized profit is greater than that, then set to profit target reached?

        Comment


          #5
          I've got it setup I think but it's not triggering a trade when I add those conditions.
          Would this be expected to work in Market Replay?

          Comment


            #6
            Hello MatthewLesko,

            Thank you for your replies and I do apologize for the delay in my reply - we've just switched to a new system for our support tickets and have a bit of a backlog.

            The above example would be expected to work on Market Replay data in the Playback connection, yes - it would not, however, show prior trades on the chart historically or work in the Strategy Analyzer.

            Please let us know if we may be of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              Problem it still makes a trade if my realized pnl is equal to or less than my loss limit if the next bar meets condition for trade.

              Comment


                #8
                Click image for larger version

Name:	mjSs91n[1].png
Views:	462
Size:	55.6 KB
ID:	1210259

                Comment


                  #9

                  I think I've come up with a work-around.
                  For my initial condition set that does the order execution, I added this:
                  Code:
                  && (SystemPerformance.AllTrades.TradesPerformance.TradesCount < 2)
                  The second set is what sets my variable to stop trading depending on profit/loss.

                  With this, I believe it will never make more than 2 trades, but if I have 2 potential trades back to back/bar to bar, if the first is profitable, it will not make a trade right after and will honor the minimum profit variable.

                  Comment


                    #10
                    Lol ok so as I piecemeal this thing now i'm confused over number of taken trades and contracts.
                    If my strategy goes entry for 5 contracts, and I run this command for output:
                    Code:
                        Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");
                    It says
                    "The strategy has taken 0 trades."
                    Then the very next entry again is exactly 5 contracts and the output says it's taken 3 trades!?!
                    How exactly is it calculating the number of trades?

                    Comment


                      #11
                      Hello MatthewLesko,

                      Thank you for your replies.

                      I would not expect the output for SystemPerformance.AllTrades.Count to be greater than 0 until at least one exit has been seen - a trade is comprised of an entry and an exit. Did any partial fills occur? If that happens, each partial fill would be counted as a separate trade.

                      Thanks in advance; I look forward to assisting you further.
                      Kate W.NinjaTrader Customer Service

                      Comment


                        #12
                        So I think with the StopTradingAfterSetPnLExample, Set 1 and Set 2 in the conditions need to be swapped.
                        It appears, that Set 1 gets processed first, and Set 2 gets processed second.
                        Set 2 is where the variable gets set. So if your trade condition happens to occur more than 2 times right in a row upon bar close, the variable won't get set until after the 3rd trade, but by then, you are either way over your profit or loss limit so it makes no sense.
                        Swapping Set 2 with Set 1 makes more sense, as the realized profit is calculated first, and variable is set first, before trades can occur that relies on the variable.

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by llanqui, Yesterday, 09:59 AM
                        4 responses
                        22 views
                        0 likes
                        Last Post llanqui
                        by llanqui
                         
                        Started by smartromain, 03-13-2024, 01:42 AM
                        5 responses
                        93 views
                        0 likes
                        Last Post AndreiBig  
                        Started by Noerclou, Today, 04:55 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post Noerclou  
                        Started by ThoriSten, Today, 03:56 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post ThoriSten  
                        Started by PhillT, 04-19-2024, 02:16 PM
                        3 responses
                        26 views
                        0 likes
                        Last Post mangel2000  
                        Working...
                        X