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

Stop entering trade when profit hit and reset

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

    Stop entering trade when profit hit and reset

    Hi ,

    How can I make the strategy to stop trading when a certain profit is hit and then reset it the next day without having to disable it

    I tried the following but this does not seem to work.


    double MyNetProfit = SystemPerformance.AllTrades.TradesPerformance.NetP rofit ;

    if (MyNetProfit >= MaxProfitHit) return;

    if (Bars.IsFirstBarOfSession) MyNetProfit = 0;

    Thanks


    #2
    Hello jpsjrj,

    Thanks for your post.

    The strategy profit accumulates each day that the strategy runs and is not reset.

    What you would need to do is to at the first bar of the session, to store the strategy accumulated PNL into a variable. Then the daily PNL would be the difference between the accumulated PNL and the saved PNL.

    Something like this:

    if (Bars.IsFirstBarOfSession)
    {
    priorPNL = SystemPerformance.AllTrades.TradesPerformance.NetP rofit ; // priorPNL would be a double type variable created at the class level as private double priorPNL
    }

    double MyNetProfit = SystemPerformance.AllTrades.TradesPerformance.NetP rofit - priorPNL; // daily PNL value


    if (MyNetProfit >= MaxProfitHit) return;
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks !! That did the trick.

      I did the same thing for GrosssLoss or Drawdown but that did not work. What do I need to do differently. ?


      if (Bars.IsFirstBarOfSession) {
      priorDrawDown = SystemPerformance.AllTrades.TradesPerformance.Curr ency.Drawdown ;
      priorGrossLoss = SystemPerformance.AllTrades.TradesPerformance.Gros sLoss;
      }


      double MyCurrentDrawn = SystemPerformance.AllTrades.TradesPerformance.Curr ency.Drawdown + priorDrawDown ;

      double MyGrossLoss = SystemPerformance.AllTrades.TradesPerformance.Gros sLoss + priorGrossLoss ;


      if (MyCurrentDrawn > 200) return;

      if (MyGrossLoss > 200 ) return;

      Comment


        #4
        Hello jpsjrj,

        Thanks for your reply.

        I would suggest using print statements to print out those values to help clarify what your strategy is using and working with.



        Paul H.NinjaTrader Customer Service

        Comment


          #5
          Hello jpsjrj,
          GrossLoss and DrawDown are shown as negative numbers in strategy analyzer. Thus, I would assume, you need to change the code:

          if (MyCurrentDrawn*-1 > 200) return;
          if (MyGrossLoss*-1 > 200 ) return;
          Or
          if (MyCurrentDrawn < -200) return;
          if (MyGrossLoss < -200 ) return;

          NT-Roland

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by rajendrasubedi2023, Today, 09:50 AM
          1 response
          10 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by geotrades1, Today, 10:02 AM
          0 responses
          4 views
          0 likes
          Last Post geotrades1  
          Started by ender_wiggum, Today, 09:50 AM
          0 responses
          4 views
          0 likes
          Last Post ender_wiggum  
          Started by bmartz, Today, 09:30 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_Erick  
          Started by geddyisodin, Today, 05:20 AM
          3 responses
          24 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X