Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Difficulty with LosingTrades.Count

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

    Difficulty with LosingTrades.Count


    Hi there, I'm having difficulty with SystemPerformance.AllTrades.LosingTrades.Count In my code, I have a statement to the effect of:

    if (During Trading Hours) AND (SystemPerformance.AllTrades.LosingTrades.Count > 1) then no more trades for the day.

    When I load up a chart, and then activate my strategy, the strategy is backrun over all of the bars in the chart. So when the strategy is caught up to the current time, the LosingTrades.Count is already a substantial number. That is, just by activating my strategy in a chart, the strategy executes over all of the bars in the existing chart. From this, LosingTrades.Count is already in a range of 3-7 by the current time. So, given this statement, my strategy then fails to execute any more trades, even though it never executed any trade during real-time.

    How can I get the LosingTrades.Count to be set to 0, or effectively employ as a circuit breaker if my strategy makes more than one bad trade, during trading hours? Thanks




    #2
    Hello timmbbo,

    Thanks for your message.

    You could consider using SystemPerformance.RealtimeTrades instead of SystemPerformance.AllTrades, and this will only reflect the trades that were made after you enabled the strategy (historical trades are excluded)

    https://ninjatrader.com/support/help...timetrades.htm

    Then to disable the strategy with Stop/Cancel/Close behavior, you can call CloseStrategy();

    CloseStrategy() - https://ninjatrader.com/support/help...sestrategy.htm

    Another example that may be helpful is our "Stopping a strategy after consecutive losers" example - https://ninjatrader.com/support/help...after_cons.htm

    Let us know if there is anything else we can do to help.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    81 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    150 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    79 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    52 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    59 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X