Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to set up stop loss with Daily number of losing trades

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

    How to set up stop loss with Daily number of losing trades

    Hi,

    I want to set up a stop loss when I have one losing trade with the strategy. I know that Ninja provides System performance class to handle this but when I use SystemPerformance.AllTrades.LosingTrades.Count it does not perform as I expect. Here is the code I use:

    if (SystemPerformance.AllTrades.LosingTrades.Count - CumulativeLosingTrade >= DailyStoplossLimit)
    {
    return;
    }

    if (Times[0][0].TimeOfDay > Times[0][1].TimeOfDay)
    {
    CumulativeLosingTrade = SystemPerformance.AllTrades.LosingTrades.Count; //This is to get total number of stop loss before today.
    }

    When I tested # of losing trade with the following code in Onbarclose function:

    Print("Current total number of losing trades: " + SystemPerformance.AllTrades.LosingTrades.Count);
    Print("Current cumulative historical number of losing trades:" + CumulativeLosingTrade.ToString());

    I see 0 only, and even there is a losing trade already during the test, the number does not update. So I want to ask how I should use the class correctly for my stop loss condition.

    I look forward to your assistance.

    Thanks!

    #2
    Hello RandomTrader,

    How are you submitting orders? The strategy performance collection only works with managed/unmanaged strategy orders. Also this specific strategy needs to submit those orders, if you are working with multiple scripts that would explain the 0.

    Comment


      #3
      Hi Jesse,

      I am testing my strategies using playback and sim accounts. I don't know if they are managed or unmanaged orders. Could you suggest how I should use the class correctly?

      Thanks!

      Comment


        #4
        Hello RandomTrader,

        You would be using managed or unmanaged as long as you are not using ATM strategies or the Addon framework. If you used the strategy builder its managed. If you manually coded it then you will have to refer to your code to see which approach you are using.

        Alternatively try using the AllTrades count to see if any trades are seen at all. SystemPerformance.AllTrades.Count

        Comment


          #5
          Hi Jesse,

          I found that when I load my strategy from the main control window, I do not see any update of the number, I tried all trades, losing and winning trades. However, if I load the strategy from the chart, I can see the update of the number. Is there any difference in the two ways of enabling strategies?

          Plus, when I am actually running the strategy, I found that there is always one losing trade at the beginning, even though on the chart I do not see one, and my restriction using losing count < 1 does not work. I wonder why.

          Thanks!

          Comment


            #6
            Just an FYI ... the EKlecticCoreV4 package provides the functionality you're asking for.

            Comment


              #7
              Hello,

              With that detail you need to either use a chart which includes backtestable data or toggle IncludeTradeHistoryInBacktest to true.



              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              558 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              324 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              545 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              547 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X