Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Unrealized Profits

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

    Unrealized Profits

    Hi,

    Is there a way to lock in unrealized profits in a script? See example below:


    If max unrealized profit in a trade is $200 and if unrealized profit drops from $200 by 20% to $160, then close the position.

    Thanks!


    #2
    Hello AgriTrdr,

    Thanks for your post.

    You would need to come up with your own custom logic to calculate that specific value and then call an Exit method when that value is reached to exit the position.

    Position.GetUnrealizedProfitLoss() could be used to get the Unrealized PnL of a strategy position.

    Position.GetUnrealizedProfitLoss() Help Guide: https://ninjatrader.com/support/help...profitloss.htm

    You could consider checking if Position.GetUnrealizedProfitLoss() is greater than or equal to 200 and set a bool to true. Then, you could create a condition that checks if the bool is true and checks if Position.GetUnrealizedProfitLoss() is less than or equal to $160 and call your Exit method to exit the position.

    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Hi Brandon,

      Thank for the reply. I understand what you're saying, but this would be more dynamic and percentage based and not specific dollar amount. Let's say 20% less profit from any dollar amount.

      Thanks
      Last edited by AgriTrdr; 04-01-2024, 01:27 AM.

      Comment


        #4
        Hello AgriTrdr,

        Thanks for your notes.

        You could add custom logic to your NinjaScript strategy to calculate a certain percentage from a set amount.

        For example, if you have a user-defined input set to 200, you could multiply 0.2 by the user-defined variable to get 20 percent of that value (40) and save it to a variable. Then subtract the user-defined input by the calculated percent variable to get the dollar amount (200 - 40 = 160) and assign that calculated value to a variable.

        That calculated value could then be used for conditions to determine if the Position.GetUnrealizedProfitLoss() is less than or equal to the calculated value.

        Please let us know if we may assist further.
        <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        62 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        134 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        75 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