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 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 rbendson, Today, 08:18 PM
        0 responses
        2 views
        0 likes
        Last Post rbendson  
        Started by TheTechnician86, Yesterday, 05:47 PM
        2 responses
        18 views
        0 likes
        Last Post TheTechnician86  
        Started by bigc0220, 09-18-2018, 09:16 AM
        8 responses
        2,615 views
        0 likes
        Last Post bsteeze
        by bsteeze
         
        Started by bortz, 11-06-2023, 08:04 AM
        54 responses
        2,113 views
        0 likes
        Last Post rene69851  
        Started by DawnTreader, 05-08-2024, 05:58 PM
        24 responses
        104 views
        0 likes
        Last Post DawnTreader  
        Working...
        X