Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit a position immediately when the Unrealized PnL is lower than (numeric value)

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

    Exit a position immediately when the Unrealized PnL is lower than (numeric value)

    Hello Ninja Traders,

    I have a strategy builder problem that has so far eluded me. My current strategy is 89% winning trades, but the losing trades are so far in the red it still makes the overall outcome a net loss.

    I understand that I should be avoiding these losing trade entries, and I'm working to define conditions to do just that. HOWEVER.... in the meantime...

    My specific strategy builder question (as support cannot offer trading advice):

    How can I create a condition that immediately exits a trade when the Unrealized PnL is lower than X, say -$25 for example?

    I've put a condition in the say "If Unrealized profit is less than numerical value of -25" as a condition to exit long position, but it appears to completely ignore this condition and just bleeds deeply.

    Even more confounding - if I define a condition to say "If Unrealized profit is greater than numerical value of +25" for a condition to exit long position, for example - it exits every time.

    This is my only exit condition, as I am testing to try to understand how it is working:

    Click image for larger version

Name:	image.png
Views:	982
Size:	13.9 KB
ID:	1245929

    What am I missing?
    Attached Files
    Last edited by christrading6267; 04-13-2023, 12:28 AM.

    #2
    Hello christrading6267,

    Thank you for your post.

    Based on your screenshots, the strategy should exit when the PnL goes below -$25. You mentioned, "it appears to completely ignore this condition and just bleeds deeply." Is this happening in real-time or on a backtest of your strategy? In real-time when the strategy is calculating On Price Change, the strategy would be able to calculate the Unrealized PnL intrabar and submit an exit as soon as the condition is met. If calculating On Bar Close or during a backtest, the actions won't necessarily occur intrabar and could be the cause of what you are reporting.

    I have created a basic example that works in real-time only. The Unrealized PnL limit is set up as a user input, so the value may be changed. It defaults to -25. I have attached the strategy in case you'd like to test it out to observe the real-time behavior.

    If you are backtesting your strategy in the Strategy Analyzer or reviewing historical performance of the strategy, the standard order fill resolution fills orders based on OHLC prices of a bar which could result in a discrepancy of prices that you would observe in real-time vs. the backtest. This is explained here:


    You could use High Order Fill Resolution as long as your strategy is not a multi-time frame or multi-instrument strategy to use more granular data in your backtest to calculate the order fills:


    Otherwise, you could script manually in an unlocked script and develop your strategy to submit orders to a more granular data series for intrabar granularity as demonstrated in this reference sample:


    Please let us know if we may be of further assistance.
    Attached Files

    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
    132 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
    49 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X