Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to capture highest gross realized pnl

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

    How to capture highest gross realized pnl

    My current strategy makes multiple trades long or short during the trading session and the profit target for each trade will vary depending on how far the current realized gross pnl is from the highest realized gross pnl achieved during the strategy

    for now I have a variable set before OnStateChange and when the strategy achieves a new high for gross realized pnl, I manually stop the strategy, type in the new value and compile.

    how and where can I write the variable so that it automatically captures the highest realized gross pnl and have it update automatically during the strategy’s life?

    #2
    Hello

    You would likely need to add a private variable for that use case. The existing user input could be used to set a private variable value from State.Configure. later in your logic when you want to use the value you would reference the private variable instead of the user input. you could then reset the private variable while the script is running.

    Comment


      #3
      thanks for the response.

      As for the logic I will have two updating variables

      HighestGrossRealizedPnL = ?
      CurrentGrossRealizedPnl = Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar)

      these values will both begin at 0.
      I am confused as how I would go about capturing the highest value in an updating variable.

      Comment


        #4
        Hello Don22Trader1,

        You would need to write logic to do that if you want to find the highest or lowest value for a given time. As I am not sure what your overall goal is it would be difficult for me to advise something specific, you may be able to do something as simple as checking if the current value is greater/lesser than your variable.

        Code:
        double currentValue = Account.Get(AccountItem.GrossRealizedProfitLoss, Currency.UsDollar)
        if(currentValue > CurrentGrossRealizedPnl)
            CurrentGrossRealizedPnl  = currentValue;
        This would just set the variable if a higher value was observed. You would also need to reset your variable to 0 at some point when you wanted to have this check for a highest value again.



        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        56 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        133 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        73 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        45 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        50 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X