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
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
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.
Paul H.NinjaTrader Customer Service
-
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.
Paul H.NinjaTrader Customer Service
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.
Paul H.NinjaTrader Customer Service
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.Paul H.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by bmartz, Today, 09:30 AM
|
2 responses
11 views
0 likes
|
Last Post
by bltdavid
Today, 11:24 AM
|
||
Started by f.saeidi, Today, 11:02 AM
|
1 response
3 views
0 likes
|
Last Post Today, 11:08 AM | ||
Started by geotrades1, Today, 10:02 AM
|
4 responses
12 views
0 likes
|
Last Post
by geotrades1
Today, 11:08 AM
|
||
Started by rajendrasubedi2023, Today, 09:50 AM
|
3 responses
16 views
0 likes
|
Last Post Today, 10:57 AM | ||
Started by lorem, Today, 09:18 AM
|
2 responses
11 views
0 likes
|
Last Post Today, 10:55 AM |
Comment