So the problem is that realized PnL in case of losses is shown with a minus sign (- $ 100 for example). So I need to somehow multiply realized PnL by -1 so that the strategy can compare them ..? If I use my Input value for this it seems impossible. Perhaps there are some other methods?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Compare unrealized PnL with realized one
Collapse
X
-
Compare unrealized PnL with realized one
Please help me compare unrealized PnL with realized one. I do this through the Strategy Builder. One of the values should be my input (unrealized PnL in currency, for example), so that I can create a condition like: if the realized PnL is greater equal to unrealized PnL. The idea is to cure losses if any ...
So the problem is that realized PnL in case of losses is shown with a minus sign (- $ 100 for example). So I need to somehow multiply realized PnL by -1 so that the strategy can compare them ..? If I use my Input value for this it seems impossible. Perhaps there are some other methods?
Tags: None
-
Hello Aporshnev,
Thanks for your post.
I do not know if this can work for you but I would suggest creating a double type custom series (in the additional data window> Custom series) as you are able to perform math via the Offset on custom series.
Then in a set use the condition Strategy>MarketPosition, Not Equal, Strategy>MarketPosition> Flat. In the action side you can assign the realized PNL to the current bar of the custom series (under Misc> Set (name of series). This is to get the realizedPNL into the series.
In the set where you wish to check realized to unrealized you would select Misc>Custom series> (name of series) (which holds the realizedPNL) and can now offset with a times -1.
Reference: "How to offset an item value" https://ninjatrader.com/support/help...on_builder.htm
Alternatively, you can unlock the strategy builder strategy and work directly in Ninjascript.
-
Thank you, the solution turned out to be useful. If possible, I will ask another question: the method above allows to work with a fixed value and perform math for further condition, nevertheless, is it possible to make a direct comparison of the realized pl with the unrealized pl through the strategy builder?
I do not have enough qualifications to work with an unlocked script directly ...
Thank you.
Comment
-
Hello Aporshnev,
Thanks for your reply.
For common understanding, RealizedPNl is what the PNL of the strategy is accumulated over the history of tsades of the Strategy. Unrealized PNL is the active trade (if any) PNL which the value would depend on the moment when it is checked. So yes you could compare then two when you are in a market position that is not flat.
Comment
-
Thank you for the clarification. My idea is that if there is a negative result from closed trades, by opening another position, the strategy compares unrealized PnL with realized ones and closes the position when they are equal.
Therefore, I am interested in how they can be compared in order to establish this as a condition.
Can you please clarify how can I compare them using strategy builder?
Comment
-
Hello Aporshnev,
Thanks for your reply.
Using your idea to multiply the PNL * -1 in the custom series will provide the opposite result, IE a positive value when PNl is less than zero You can then compare the unrealized PNl (when you are in aposition) with the custom series PNL proxy and if Greater or equal to then exit the position.
Comment
-
Thank you for your reply and for your efforts in helping me. I have already implemented what you write about and tested it - yes, it works well, however, this is a comparison with the "proxy" PnL. This can only serve well as a driver for activating a condition (necessary variable, etc.) The result is not always accurate, since the number in the custom series is never equal to the exact PnL - there is always an offset either up or down (due to commissions, etc.). Therefore, what I want to achieve is to make the most accurate comparison of the realized versus the unrealized, in order to exit a position with zero loss.
Comment
-
Hello Aporshnev,
Thanks for your reply.
The strategy, in the Strategy Builder, only knows of the RealizedPNL it can access.
As a workaround, you may wish to add a further offset.
If you would like your strategy created for your specific needs, we can provide a link to 3rd party programmers who can provide that service.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
56 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
132 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
73 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
49 views
0 likes
|
Last Post
|

Comment