Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

AllTrades.Count & Default Quantity

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

    AllTrades.Count & Default Quantity

    I have a simple script with EnterLong and 2 Exit orders with the same signal name for SL and TP. I seek to count number of trades, also winning and losing trades.

    When I have the Quantity set to 1 in my strategy settings and the entires per direction also set to 1. Everything works perfect. Every time an order executes.(Enter&Exit) The AllTrades.Count increases by +1. This works exactly as I would expect.

    However, if I increase the Quantity in the strategy settings, then AllTrades.Count returns different results and I cannot work out what's it doing. I get the following:

    * The strategy has 0 historical trades.

    A. Quantity = 1
    1st completed trade AllTrades.Count = 1
    2nd completed trade AllTrades.Count = 2

    B. Quantity = 2
    1st completed trade AllTrades.Count = 2
    2nd completed trade AllTrades.Count = 4

    C. Quantity = 4
    1st completed trade AllTrades.Count = 2
    2nd completed trade AllTrades.Count = 6

    D. Quantity = 8
    1st completed trade AllTrades.Count = 2
    2nd completed trade AllTrades.Count = 8
    3rd completed trade AllTrades.Count = 11

    Winning.Count also returns the same number. How is this working exactly? When the quantity is anything other than 1 it doesn't return the number I expect. For example, when I have the quantity set to 8. After the first trade the count shows 2 trades, then after the next it goes to 10, then the next 11. Whilst it doesn't seem random, it makes no sense to me.

    How do I have the quantity be anything other than 1 and have the AllTrades.Count return the number of trades as per the number of trades?


    Last edited by lucyb; 07-02-2024, 02:36 PM.

    #2
    Hello lucyb,

    It looks like this relates to your existing post, in the future please make sure to reply back to your existing posts if the question pertains to something you had already been discussing in that post.


    If we use a very simple test like the following code you should see that for 1 quantity 1 entry + 1 exit equals 1 trade so the count is 1. For a quantity of 2 we would see 2 trades and so on.


    Code:
    private bool doOneTime;
    protected override void OnBarUpdate()
    {
       if (State != State.Realtime)
          return;
       
       Print(SystemPerformance.AllTrades.Count);
    
       if(doOneTime == false)
       {
          SetStopLoss(CalculationMode.Ticks, 10);
          SetProfitTarget(CalculationMode.Ticks, 10);
          EnterLong("Test");
          doOneTime = true;
        }
    
    }​

    This places a single trade in realtime, you can manually move the targets to fill to force a trade to complete. If you increase the quantity to 2 then two entries are submitted and will have two associated exists meaning 2 trades.


    Without seeing your code I couldn't really comment on the counts you are seeing, we would need to be able to see the code in addition to the performance report to know that it matches. It would be easier to test using a script like the code I provided her so you can experiment in realtime without historical processing to make sure you understand how the count is incremented per each quantity you use. The counts you are seeing may be a result of some orders not being filled or partial fills, when partial fills occur those are also considered an individual trade because its a paired entry + exit.

    Comment


      #3
      Hi. Thanks. So I ran your script. What I noticed was. Depending on where I moved the playhead to depending on how the order was filled.

      With a quantity set to 4 and entries per direction set to 1. Sometimes it would fill all in 1 execution and then the count was 1. In other areas, it would do the same order in 4 executions so the count was 4.

      So I guess the script behaves exactly like mine and its partial fills that increasing the count which is what confuses me. So in my case, if I backtest my strategy for a day and at the end it shows 20 trades. I don't know if this is 20 actual trades or 7 trades that had various partial fills and the count is 20.



      Comment


        #4
        Hello lucyb,

        Yes that sounds normal, partial fills are still trades because you have an entry and an exit, it does not need to be the total quantity. If you want to make sure you have no partial fills you would have to use 1 quantity for your orders to prevent that from happening.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Today, 05:17 AM
        0 responses
        26 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        122 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        64 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        41 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        46 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X