Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Accessing Trade Performance via Strategy Builder

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

    Accessing Trade Performance via Strategy Builder

    Hi. I test my strategy day by day in Market replay. At the end of each day I would like to know:

    - Number of Triggers
    - Number of Trades
    - Number of Wins
    - Number of Losses

    I've just gotten to the stage where I unlock my strategies and have dabbled in code. Comparing variables and such like. But I'm unsure how to get the above info

    For counting the triggers, I can manage to create a variable and increment it everytime the trigger conditions are met and then print this out at the end. But the other information above can be accessed another way for efficiently correct?


    #2
    Hello lucyb,

    In the builder those metrics are not available but in unlocked code you can get all of those items from the strategies performance. Using a variable for a counter for triggers would be the best way to approach that part. You can find samples of each of the other metrics below.





    Because these collections include both historical and realtime trades doing this day by day would require using logic to know the session the values. The following sample shows how to do that with the strategies PnL, it would be the same concept for any other item like trade counts. You would need to store the total number of trades for the previous days to a variable on the first bar of the session and then subtract that from the actual total to know the difference which would be the amount for the session.


    Comment


      #3
      Thanks.

      Could you help me though. I put this into my code:

      Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");

      Yet it constantly returns 0 trades even after the strategy has made a trade. What am I missing? I'm testing in MarketReplay.
      Last edited by lucyb; 07-02-2024, 09:19 AM.

      Comment


        #4
        Hello lucyb,

        When you say the strategy took a trade, was that an entry + exit? That only counts entry + exits which is what a trade consists of.

        Once a strategy has a completed trade that collection will get updated. Keep in mind that only works for the current instance, if the strategy placed a trade and then you disabled it the count should be 0 because it was restarted.

        Comment


          #5
          Hey yes it was an entry with associated exit;

          EnterLongLimit(Convert.ToInt32(DefaultQuantity), (High[1]), @"myLong");

          then

          ExitLongStopMarket(Convert.ToInt32(DefaultQuantity ), MyStop, "", @"myLong");
          ExitLongLimit(Convert.ToInt32(DefaultQuantity), MyProfit, "", @"myLong");

          It's also in the current instance. I have 3 successful trades with visible p&l and the examples above:

          Print("The strategy has taken " + SystemPerformance.AllTrades.Count + " trades.");

          and also:

          SystemPerformance.AllTrades.WinningTrades.Count

          simply return 0 all the time.

          Comment


            #6
            I've attached my code. I simplified the conditions to submit a trade if there's 2 same color candles in a row for testing.

            The prints are in Set 10 and are set to print every price change.
            Attached Files
            Last edited by lucyb; 07-02-2024, 09:43 AM.

            Comment


              #7
              Hello lucyb,

              The image shows active orders so the count should be 0 for that situation, both the entry and its associated exit need to fill to be a trade.

              Comment


                #8
                Hello, in the image there had already been 3 trades by this point. Please see attached image. Taken immediately after the previous image's stop loss was hit.
                Attached Files

                Comment


                  #9
                  Hello lucyb,

                  Where are you printing the count from? I can see this working fine on my end by using a modified sampleMACrossover and then printing the count from OnBarUpdate.

                  Another item which would affect that count would be if you have applied the strategy to the control center where IncludeTradeHistoryInBacktest is false, you need to apply it to the chart or set IncludeTradeHistoryInBacktest to true and then remove and re apply it.

                  Comment


                    #10
                    I don't see that setting in my strategy settings at all. So I never touched anything regarding that.

                    Wherever I put the prints inside

                    protected override void OnBarUpdate()

                    The result is 0. At the start and after every single successful trade.
                    Attached Files

                    Comment


                      #11
                      Hello lucyb,

                      You either need to explicitly add that property to your scripts SetDefaults or you need to apply the strategy directly to a chart for trade performance to be used. If you apply the strategy to the control center its not going to collect trade performance information. From your images I cant tell if the strategy was applied to the chart or not because no trades are visible in the chart, if you used the control center remove the strategy and re apply it directly to the chart.

                      Comment


                        #12
                        Yea I dunno why it's not working. I add my strategy the same as always. I right click in control centre > new strategy. Then I select the instrument of the chart.

                        All the trades are going through and everything works when I hit play. I can see the executions in the log and the orders go through the output. It's just this print commands related to trades just returns constantly 0.

                        See attachments. You can see my strategy is applied to the correct chart and the settings of it.
                        Attached Files

                        Comment


                          #13
                          Hello lucyb,

                          That is what I said will not work, you are applying it to the control center where trade performance information is not used. You need to follow either of the options I provided. Either set the property IncludeTradeHistoryInBacktest to true in State.SetDefaults in your code so it can be used in the control center or apply the strategy to a chart and not the control center.

                          Comment


                            #14
                            ok thanks. I was confused I didn't know that there's 2 ways to add a strategy to a chart. It works if I right click and add it to the chart there. I

                            When strategies are listed in control centre. How do you differentiate between strategies added into control centre and ones that are applied to the chart? They look the same.

                            Comment


                              #15
                              Hello lucyb,

                              There is not a way to differentiate the strategies in the control center, you would need to view the chart to see if the strategies label is in the chart, if so it is applied to that chart. When applied to a chart you will also see text and markers for executions the strategy makes and connecting lines where you will not see that when applying the strategy to the control center.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by NullPointStrategies, Today, 05:17 AM
                              0 responses
                              44 views
                              0 likes
                              Last Post NullPointStrategies  
                              Started by argusthome, 03-08-2026, 10:06 AM
                              0 responses
                              124 views
                              0 likes
                              Last Post argusthome  
                              Started by NabilKhattabi, 03-06-2026, 11:18 AM
                              0 responses
                              65 views
                              0 likes
                              Last Post NabilKhattabi  
                              Started by Deep42, 03-06-2026, 12:28 AM
                              0 responses
                              42 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