Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

End Strategy on Realized Profit

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

    End Strategy on Realized Profit

    Is there a way to end strategy once relaized profit of say one pt is reached for the day?

    #2
    lvaduva,

    This can be done through custom programming. Please see this reference sample: http://www.ninjatrader-support2.com/...ead.php?t=4084
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      I tried

      if (Performance.RealtimeTrades.TradesPerformance.Curr ency.CumProfit >= 130 || Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit <= 500)
      {
      return;
      }


      I tried the above code in simulation trading and it does not stop strategy upon 130 profit....is there anything wrong in the code. I followed the example put in the link

      Comment


        #4
        If you are not in real-time you should not use .RealtimeTrades.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          I am in real time...the price is changing and i am watching it. what i mean by simulation is that i am not using real money.

          Comment


            #6
            Suggest you try printing the value of Performance.RealtimeTrades.TradesPerformance.Curre ncy.CumProfit to see what it is being evaluated as along the way.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              How do I print that and where do i check the print out?

              Comment


                #8
                You can just use the Print() method. Put in whatever you want to print inside the parenthesis. It will show up in the Tools>Output Window.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Code

                  The code is doing what it is suppose to but the strategy does not stop it keeps trading. Can you see if you can find bug?
                  Attached Files

                  Comment


                    #10
                    lvaduva, try placing the code snippet to stop trading before all the other parts of the strategy, not after.
                    Code:
                       
                    protected override void OnBarUpdate()
                    {
                         if(Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit > 130 || Performance.RealtimeTrades.TradesPerformance.Currency.CumProfit < -500)
                             return;
                    
                    // the rest of your code goes here
                    }
                    AustinNinjaTrader Customer Service

                    Comment


                      #11
                      Thanks Ausitn that works great. Now one last question, if I wanted to run this in backtest, do I need to change .RealtimeTrades. to something else?

                      I was also curious, in backtest if I choose to trade only between 9am and 4pm are the ema averages affected by this versus if I choose 12am to 12am?

                      Comment


                        #12
                        In backtest, you could try .AllTrades.

                        Depends how you decide to limit the time. If you limit it by Start/End times of the sessions then the EMAs will only be calculated based on that time range. If you limit trading through code but leave start/end as 12am-12am then the EMAs will not be limited.
                        Josh P.NinjaTrader Customer Service

                        Comment


                          #13
                          oh i didn't know i could limit through code....do you have an example of this, i'd really like to make that part of my core code. or maybe let me know the function, i'd really appreciate it.

                          Comment


                            #14
                            Please see: http://www.ninjatrader-support2.com/...ead.php?t=3226
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              I have a problem in backtesting. While in back testbacktest I would like to have the strategy evaluated such that once a price target is hit or a stop loss target is hit daily in the back test, the strategy would stop trading untill the next day and then begin again. Here is what I coded, but this makes the strategy take only one trade and then stops in the backtest. How can I modify so that it continues as outlined above for the whole time period, about a month?

                              protectedoverridevoid OnBarUpdate()
                              {
                              // At the start of a new session
                              if ((ToTime(Time[0]) >= 90000 && ToTime(Time[0]) < 160000))
                              {
                              if(Performance.AllTrades.TradesPerformance.Currency. CumProfit > 200 || Performance.AllTrades.TradesPerformance.Currency.C umProfit < -1350)
                              {
                              return;
                              }




                              // Condition set 1
                              if (CrossAbove(EMA(Median, 4), SMA(Median, 21), 1) && Position.MarketPosition == MarketPosition.Flat)
                              {
                              EnterLong(DefaultQuantity,
                              "");


                              }
                              }
                              }

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              633 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              105 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              568 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X