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 sofortune, Yesterday, 11:48 AM
        2 responses
        22 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by Zach55, 02-19-2024, 07:22 PM
        2 responses
        54 views
        0 likes
        Last Post lbadisa1  
        Started by JGriff5646, Today, 05:47 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by AlphaOptions, 06-18-2013, 08:24 AM
        9 responses
        2,200 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by ttrader23, Today, 09:33 AM
        3 responses
        23 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Working...
        X