Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Daily profit target

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

    Daily profit target

    I'm trying to stop a strategy for the day if a certain size win occurs without using (Bars.FirstBarOfSession)

    It works fine on the first day except it just stops after hitting the first daily target and doesn't seem to be resetting each day.

    I'm not sure what I'm missing here:

    private int largestWIN = 0;
    private int currDay = 0;


    protected override void OnBarUpdate()
    {
    if(Time[0].Day != currDay)
    largestWIN = 0;

    if(Performance.AllTrades.Count > 0 && largestWIN == 0)
    {Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

    if(lastTrade.ProfitPoints > 10)
    {largestWIN = 1;
    currDay = Time[0].Day;
    }
    }

    if(largestWIN == 1)
    return;

    //entry stuff
    }

    #2
    Hello dexter_es,
    It may be the case that the profit point of the last trade is < 10.

    Please use the Print function to print our the values in the Output window (File>Output Window) and verify the values and see how exactly the strategy is behaving.

    For more debugging tips please refer to this post which further discusses it.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thanks for getting back to me Joydeep.

      I've used the print function and everything seems ok with the profit target, the strategy will trade everyday until the first time a trade hits the 10 point target and then it stops.

      I think it may have to do with this part:

      if(Performance.AllTrades.Count > 0 && largestWIN == 0)
      {Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1];

      If I stop after a win then my last trade will always satisfy the condition that sets largestWIN = 1

      I really need to have lastTrade = lastTrade only for the day and then reset after each day

      Comment


        #4
        Hello dexter_es,
        In such scenario you have to either use Bars.FirstBarOfSession or reset the currDay

        Code:
        if(Time[0].Day != currDay)
        {
        largestWIN = 0; 
        currDay = Time[0].Day;
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          that worked, thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          574 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X