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
pnl
Collapse
X
-
Hello ballboy11,
Thanks for your post.
If I understand correctly, you are trying to:- Collect strategy PnL from the trading session
- Check if this PnL is within a certain point
- Close the strategy depending on this condition.
Collecting PnL can be done from a TradeCollection. I would like to point out the following thread where this has been addressed recently for your reference. Sample code, explanations and documentation reference are included therein. Please leave a reply in our thread here if you have any specific questions that are not clear after testing.
Collecting PnL by creating your own TradeCollection - https://ninjatrader.com/support/foru...d.php?t=111702
This information could be used in your own condition to compare PnL with a certain level, and then the strategy can call the CloseStrategy() method to close the strategy.
CloseStrategy - https://ninjatrader.com/support/help...sestrategy.htm
I look forward to being of any further assistance.JimNinjaTrader Customer Service
-
Hello ballboy11,
The code in the linked thread references SystemPerformance.AllTrades which is a collection of all trades made by the NinjaScript strategy including trades made with historical data and with realtime data. Keep in mind, NinjaScript strategies that submit Atm strategies do not track the Atm strategy's trades/performance and the Atm strategy methods will have to be used to obtain this information.
Custom code will have to be added to your strategy to keep track of the Atm strategy ID's and then you can accumulate the realized PnL using GetAtmStrategyRealizedProfitLoss when the Atm strategy is no longer active.
Unrealized PnL can be calculated with GetAtmStrategyUnrealizedProfitLoss.
The SampleAtmStrategy NinjaScript strategy that comes bundled with NinjaTrader shows an example for how GetAtmStrategyUnrealizedProfitLoss can be used. You may wish to place a call to GetAtmStrategyRealizedProfitLoss at the beginning of OnBarUpdate() in a duplicate strategy so you can observe the strategy print the realized PnL of the AtmStrategy before a new AtmStrategyID is created for a new instance of an ATM strategy.
I've included a demo as well reviewing how the SampleAtmStrategy NinjaScript strategy uses these methods.
Demo - https://drive.google.com/file/d/1-hp...w?usp=drivesdk
I'll include our documented Atm Strategy in NinjaScript resources for the thread's reference:
Atm Strategy Methods - https://ninjatrader.com/support/help...gy_methods.htm
Using Atm Strategies with NinjaScript Strategies - https://ninjatrader.com/support/help...strategies.htm
Please let us know if you have any additional questions.JimNinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by alifarahani, Today, 09:40 AM
|
4 responses
19 views
0 likes
|
Last Post
by alifarahani
Today, 02:41 PM
|
||
Is it possible to have a drawing, such as a line, cycle through different colors?
by gentlebenthebear
Started by gentlebenthebear, Today, 01:30 AM
|
3 responses
15 views
0 likes
|
Last Post Today, 02:41 PM | ||
Started by PhillT, Today, 02:16 PM
|
2 responses
7 views
0 likes
|
Last Post
by PhillT
Today, 02:33 PM
|
||
Started by Kaledus, Today, 01:29 PM
|
3 responses
11 views
0 likes
|
Last Post Today, 02:24 PM | ||
Started by frankthearm, Yesterday, 09:08 AM
|
14 responses
47 views
0 likes
|
Last Post Today, 02:19 PM |
Comment