Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Percent winners in last "X" Number of trades

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

    Percent winners in last "X" Number of trades

    I have been looking through the forums and the help guides trying to find a way to find the percent profitable for a certain number of trades. I have looked into the TradesPerformanceValues and other similar subject. I am currently stuck with this problem and am looking for some guidance as to what I am doing incorrectly.
    My current code looks something like this.
    winningTrades = (Performance.AllTrades.WinningTrades.Count);
    allTrades = (Performance.AlllTrades.Count);
    winningPercent = (winningTrades/allTrades);


    I am having trouble making this code only look a the last 10 or so trades that have been executed.

    #2
    Hello,

    Thanks for your note.

    You would need to in this case setup a loop and loop back with the last 10 trades and then add the PnL to a variable if its positive and then take that variable and use it in your profit calculations however you need to use it.

    An example of this type of loop is here:



    Let me know if I can be of further assistance.
    BrettNinjaTrader Product Management

    Comment


      #3
      Would I be able to backtest this process with using AllTrades? Also would the amount of trades in the lookback period be able to be optimized on or would I have to manually change the number myself.

      Comment


        #4
        Hello,

        Sure you can do both. This will backtest and it you can setup a variable for the number of times the loop iterates and set this up as a parameter. Once this is done you will be able to optimize this paramter.

        Let me know if I can be of further assistance.
        BrettNinjaTrader Product Management

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cmoran13, Yesterday, 01:02 PM
        0 responses
        28 views
        0 likes
        Last Post cmoran13  
        Started by PaulMohn, 04-10-2026, 11:11 AM
        0 responses
        18 views
        0 likes
        Last Post PaulMohn  
        Started by CarlTrading, 03-31-2026, 09:41 PM
        1 response
        160 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        95 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        148 views
        2 likes
        Last Post CaptainJack  
        Working...
        X