Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop trading after first [x] trades of a day result in a cumulative loss

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

    Stop trading after first [x] trades of a day result in a cumulative loss

    Hello,

    I was trying to develop a simple script that is also based on the fact that on certain days, if eg. the first two trades result in a cumulative loss, or the first three trades are consecutive losses, the script stops all activity for the day, but resumes normal trading activity the next day.

    thank you for your help.

    #2
    Hello realblubb,

    Welcome to the NinjaTrader forums!

    Below is a link to support article with helpful resources on getting started with C# and NinjaScript.


    You can check the SystemPerformance.AllTrades collection to see if the last trade.CumProft is less than 0, and then set a bool to stop trading.



    This example below has similar logic to stop trading, but after exceeding an amount of loss.
    Hello, I've updated the DailyLossLimit and DailyLosLimitMultiTrade examples that were posted on the forum for NinjaTrader 7 for NinjaTrader 8. These are often requested and I felt they are good examples to have for NT8. DailyLossLimitExample_NT7 - http://ninjatrader.com/support/forum...241#post451241 (http://ninjatrader

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your help. I tried the following approach:


      Code:
      protected override void OnPositionUpdate(Cbi.Position position, double averagePrice,
      int quantity, Cbi.MarketPosition marketPosition)
      {
      if (SystemPerformance.AllTrades.Count > 1)
      {
      
      Trade lastTrade = SystemPerformance.AllTrades[SystemPerformance.AllTrades.Count - 1];
      if(position.Instrument==this.Instrument)
      {
      if(Position.MarketPosition==MarketPosition.Flat)tr adecount++;
      if(lastTrade.Entry.Instrument==this.Instrument)day profit+=lastTrade.ProfitCurrency;
      if(tradecount>=maxtrades&&dayprofit<0)Pause=true;
      
      }
      Print (string.Format( "Dayprofit: {0}, Tradecount: {1}, Pause: {2}", dayprofit,tradecount,Pause));
      
      }
      }
      In principle it works, but the day profit sometimes adds the same trade twice. I didnt find out exactly when (potentially when the trade stretches over one day), but it sometimes distorts the result.

      Comment


        #4
        Hello realblubb,

        It appears you are using the tradecount variable to set a bool named Pause to true. My guess is this bool is used in the condition that submits the entry, though that code was not included.

        Where is tradecount being incremented each time SystemPerformance.AllTrades.Count, and where is this being reset on a new session?

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        590 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        342 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        555 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        552 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X