Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Suggested Pattern to limit trade number of losses or wins per day

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

    Suggested Pattern to limit trade number of losses or wins per day

    I thought i would share a non verbose simple coding pattern - which saves the need to keep tabs or write a linq query for conditional statements revolving around performance losses and wins etc - caching the value bar to bar within a session/day can speed it up even more.

    It looks ok so far - I hope i don't eat my hat for posting this...
    It should be possible to use the same technique for week,month,year and any other collection.

    All we are doing is accessing a trade collection by a key - a date conveniently.
    The TradesCount property allows us to access the lenght of the collection.

    Thank you NinjaTrader...!

    Pattern for day losses
    Performance.AllTrades.LosingTrades.ByDay[dayKey]!=null && ((TradeCollection)Performance.AllTrades.LosingTrad es.ByDay[dayKey]).TradesCount>lossesByDayLimit)

    Pattern for day wins
    Performance.AllTrades.WinningTrades.ByDay[dayKey]!=null && ((TradeCollection)Performance.AllTrades.WinningTra des.ByDay[dayKey]).TradesCount>winsByDayLimit)

    onBarUpdate.....{

    //day keys syncd to bar time
    DateTime dayKey =
    newDateTime(Time[0].Year,Time[0].Month,Time[0].Day);

    //if less than 3 losses then trade allowed

    if (Performance.AllTrades.LosingTrades.ByDay[dayKey]!=null && ((TradeCollection)Performance.AllTrades.LosingTrad es.ByDay[dayKey]).TradesCount<3)
    {
    //signal condition
    }


    }

    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    #2
    Hello,

    Thanks for posting!
    BrettNinjaTrader Product Management

    Comment


      #3
      Thank you very much for the code, but i try in NT 7.0023 and dont work, the condition never happend and no entries into //signal condition.

      Could you help me to do for NT7 please?
      Thank you so much.

      ---------------

      //day keys syncd to bar time
      DateTime dayKey =
      newDateTime(Time[0].Year,Time[0].Month,Time[0].Day);

      //if less than 3 losses then trade allowed

      if (Performance.AllTrades.LosingTrades.ByDay[dayKey]!=null && ((TradeCollection)Performance.AllTrades.LosingTrad es.ByDay[dayKey]).TradesCount<3)
      {
      //signal condition
      //Never entry here
      }

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X