Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

total PNL exit

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

    total PNL exit

    Im creating a strategy that exits my current trade once todal pnl reaches $500 how could i do that?This is what i have.

    // Set 5
    if ((Position.MarketPosition == MarketPosition.Short)
    && (Position.GetUnrealizedProfitLoss(PerformanceUnit. Currency, Close[0]) >= 500))
    {
    ExitShort(Convert.ToInt32(Position.Quantity), "", "");
    }

    The problem with this is that it exits when the unrealized position gets to 500, however if i had been in several loosing trades prior, say i lost 100 and 100, id be -200 in realized profits, since my position exited when it reached 500, my total profit is 300. I want it to exit when the total pnl is 500, in this example it should have exited when my unrealized was at $700 because of my two loosing trades.

    Thanks​

    #2
    Hello jpgombot,

    Thank you for your post.

    You can get the PnL from strategy positions from the SystemPerformance collection.
    https://ninjatrader.com/support/help...erformance.htm

    See this help guide page for information about accessing the cumulative profit value (instead of the unrealized value) from the SystemPerformance.AllTrades collection:
    https://ninjatrader.com/support/help.../cumprofit.htm

    Please let us know if you have any further questions. ​​

    Comment


      #3
      Thanks for your reference

      would this give me the result im looking for based on the link you sent me?
      // Set 5

      if ((Position.MarketPosition == MarketPosition.Short)
      && (SystemPerformance.AllTrades.TradesPerformance.Cur rency.CumProfit) >= 500))
      {
      ExitShort(Convert.ToInt32(Position.Quantity), "", "");
      }

      Is ninjascript only for inhouse ninja trader professional coders? if not do you guys have a dictionary of what the programming terms mean. For example how would a non professional coder know that cumprofit is the same and total Pnl as shown on your platform user face, thats if they are? alltrades, is that all trades for the day or for the entire life of the contract, is that suppose to be common knowledge, i feel like im missing something here. Most post give you links back to the support which i find dont have in depth explanation of what the methods or functions do, they are very vague print examples.

      Comment


        #4
        Hello,

        Thank you for your response.

        Our support generally can't answer questions like "does this look right"/"would this work", we would redirect you to try the script and make sure it does what you are expecting. Testing the script is a very important part of the strategy creation process so that squarely falls on the developer to make sure it works as planned.

        Your condition will check if the strategy's current market position is short and if the cumulative profit is greater than or equal to $500.


        NinjaScript is not only for professional coders, however, a basic understanding of C# programming is a prerequisite to writing NinjaScript code.



        Cumulative Profit and Total PnL are not necessarily coding terms but general trading terms/jargon.

        All NinjaScript-specific information can be found documented in the Help Guide.

        AllTrades is a collection of all trades generated by a strategy. The Help Guide for this is below:



        Please let us know if you have any further questions.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by NullPointStrategies, Yesterday, 05:17 AM
        0 responses
        54 views
        0 likes
        Last Post NullPointStrategies  
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        130 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        72 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        44 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        49 views
        0 likes
        Last Post TheRealMorford  
        Working...
        X