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 GLFX005, Today, 03:23 AM
          0 responses
          2 views
          0 likes
          Last Post GLFX005
          by GLFX005
           
          Started by XXtrader, Yesterday, 11:30 PM
          2 responses
          11 views
          0 likes
          Last Post XXtrader  
          Started by Waxavi, Today, 02:10 AM
          0 responses
          7 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Started by TradeForge, Today, 02:09 AM
          0 responses
          14 views
          0 likes
          Last Post TradeForge  
          Started by Waxavi, Today, 02:00 AM
          0 responses
          3 views
          0 likes
          Last Post Waxavi
          by Waxavi
           
          Working...
          X