Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Exit all positions at Loss or Profit

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

  • NinjaTrader_ChrisL
    replied
    Hi Steve4616, thanks for posting. The SystemPerformance class will only provide the performance metrics of the single strategy it is being called from, not the entire account. Each strategy needs to check its own PnL value and close its position based on that calculation. You can get Account based metrics by using the Get method:


    Kind regards,
    -ChrisL

    Leave a comment:


  • Steve4616
    replied
    Originally posted by NinjaTrader_BrandonH View Post
    Hello MathWiz,

    Thank you for your note.

    CurrentPNL = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit; would save the cumulative profit of all trades to the variable CurrentPNL.

    CumProfit — https://ninjatrader.com/support/help.../cumprofit.htm

    Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]) will return the unrealized PnL for the strategy position. (Strategy positions are different from Account positions)

    Position.GetUnrealizedProfitLoss — https://ninjatrader.com/support/helpGuides/nt8/position_getunrealizedprofitloss.htm

    This means that the code you shared would check if the cumulative profit of all trades + the unrealized PnL of the strategy position is less than myDailyStoplevel and calls Flatten(). This would not be checking the unrealized PnL of your account position.

    To have the strategy monitor the unrealized PnL of your account, you would need to use PositionAccount.GetUnrealizedProfitLoss() instead of Position.GetUnrealizedProfitLoss().

    PositionAccount.GetUnrealizedProfitLoss — https://ninjatrader.com/support/help...profitloss.htm

    Please note that instead of Flatten() you would need to call Account.Flatten() as seen in the help guide example in post number 2.

    See the attached example script that demonstrates how this would be accomplished.

    Let us know if we may assist further.
    Brandon,

    I stumbled across your strategy and tried to change it into an account daily profit target as well. I'm currently using 154 strategies over 6 accounts(no SIM). Flattening each account with a different daily target and stop is very important. I changed Currency to Ticks and added the Profit Target to go along with the stop you had there. When I tried it out, it would stop the strategy on SIM101 account but seemingly at very sporadic times. I ran it on 5 second chart just so it would update often and wouldn't have to wait until the the bars close on the multiple strategies I'm running. Here is the code, do you see anything obvious why it wouldn't work properly? Thanks
    Attached Files

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello Neilpacc76,

    Thanks for your note.

    This script is meant to be an example of how to call the Account.Flatten() method when the cumulative profit of all trades + the unrealized PnL of the account position is less than MyDailyStoplevel. It is not meant to be a fully working tool.

    That said, since the script does not place trades and trades are placed manually, the Strategy Position and Account Position would go out of sync. Strategies are not able to detect trades placed manually or placed by other strategies. For example, if the Strategy Position is 0 and the Account Position is 0, then a trade is placed manually, the Account Position would be 1 and the Strategy Position would be 0 since the strategy did not place the trade. This would cause the Strategy Position and Account Position to be out of sync.

    See this help guide page for more information: https://ninjatrader.com/support/help..._account_p.htm

    Let us know if we may assist further.

    Leave a comment:


  • Neilpacc76
    replied
    Hello,
    I am hoping you can help me with this script? I downloaded it and changed the account name to my "Playback101" so it matched and I updated the instrument to "ES 06-22" and changed the properties setting to allow a negative number to allow for max loss.
    When I start my strategy and this one on the playback101, they are both in "Sync" until it opens a trade and then the CumProfit script "Sync" errors and shows "False" and doesn't work??
    I did also try it on a live feed Sim101 account and it did the same?
    Please help, thanks.

    Leave a comment:


  • NinjaTrader_BrandonH
    replied

    Hello MathWiz,

    Thank you for your note.

    CurrentPNL = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit; would save the cumulative profit of all trades to the variable CurrentPNL.

    CumProfit — https://ninjatrader.com/support/help.../cumprofit.htm

    Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0]) will return the unrealized PnL for the strategy position. (Strategy positions are different from Account positions)

    Position.GetUnrealizedProfitLoss — https://ninjatrader.com/support/helpGuides/nt8/position_getunrealizedprofitloss.htm

    This means that the code you shared would check if the cumulative profit of all trades + the unrealized PnL of the strategy position is less than myDailyStoplevel and calls Flatten(). This would not be checking the unrealized PnL of your account position.

    To have the strategy monitor the unrealized PnL of your account, you would need to use PositionAccount.GetUnrealizedProfitLoss() instead of Position.GetUnrealizedProfitLoss().

    PositionAccount.GetUnrealizedProfitLoss — https://ninjatrader.com/support/help...profitloss.htm

    Please note that instead of Flatten() you would need to call Account.Flatten() as seen in the help guide example in post number 2.

    See the attached example script that demonstrates how this would be accomplished.

    Let us know if we may assist further.
    Attached Files

    Leave a comment:


  • MathWiz
    replied
    George,

    Are you saying that code like this:

    CurrentPNL = SystemPerformance.AllTrades.TradesPerformance.Curr ency.CumProfit;

    if (CurrentPNL + Position.GetUnrealizedProfitLoss(PerformanceUnit.C urrency, Close[0])) < myDailyStoplevel)
    {
    Flatten()
    }

    running as its own strategy will monitor my entire account and flatten all positions if it reaches its trigger?

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello George1455,

    Thank you for your note.

    NinjaTrader 7 does not have the ability to subscribe to the account-based event AccountItemUpdate. Instead, you would need to create a condition that checks if GetAccountValue(AccountItem.RealizedProfitLoss) is less than or greater than a certain value followed by calling Exit methods such as ExitLong/ExitShort to close out of your positions.

    GetAccountValue() - https://ninjatrader.com/support/help...countvalue.htm
    Order methods - https://ninjatrader.com/support/help...d_approach.htm

    If you have further questions regarding this, please open a new forum thread in the NinjaTrader 7 Strategy Development section of the forums.

    Let us know if we may assist further.

    Leave a comment:


  • George1455
    replied
    Originally posted by NinjaTrader_BrandonH View Post
    Hello MathWiz,

    Thank you for your post.

    You could create a strategy that subscribes to the account-based event AccountItemUpdate to monitor the total account PnL. You would then create a condition in your script that checks if the Unrealized account PnL plus the Realized account PnL is less than a certain price value and call Flatten() to flatten all positions. Another condition would be created in the script that checks if the Unrealized PnL plus the Realized PnL is greater than a certain price value and call Flatten().

    Public documentation for AccountItemUpdate can be referenced here - https://ninjatrader.com/support/help...itemupdate.htm

    AccountItems that can be used are documented here - https://ninjatrader.com/support/help...ccountitem.htm

    See this documentation for information about Flatten() — https://ninjatrader.com/support/help...ghtsub=flatten

    Let us know if we may further assist.
    Can you please give some advises/links/examples for NT7 as well ?
    Thanks

    Leave a comment:


  • NinjaTrader_BrandonH
    replied
    Hello MathWiz,

    Thank you for your post.

    You could create a strategy that subscribes to the account-based event AccountItemUpdate to monitor the total account PnL. You would then create a condition in your script that checks if the Unrealized account PnL plus the Realized account PnL is less than a certain price value and call Flatten() to flatten all positions. Another condition would be created in the script that checks if the Unrealized PnL plus the Realized PnL is greater than a certain price value and call Flatten().

    Public documentation for AccountItemUpdate can be referenced here - https://ninjatrader.com/support/help...itemupdate.htm

    AccountItems that can be used are documented here - https://ninjatrader.com/support/help...ccountitem.htm

    See this documentation for information about Flatten() — https://ninjatrader.com/support/help...ghtsub=flatten

    Let us know if we may further assist.

    Leave a comment:


  • MathWiz
    started a topic Exit all positions at Loss or Profit

    Exit all positions at Loss or Profit

    Does anybody have a single strategy that can be enabled in the Control Center daily, will monitor the account during the regular session, and will sell all positions in that account should the total of realized plus unrealized losses be less than a designated amount, or should the the total of realized plus unrealized gains be more than a designated amount?

Latest Posts

Collapse

Topics Statistics Last Post
Started by Mindset, 04-21-2026, 06:46 AM
0 responses
88 views
0 likes
Last Post Mindset
by Mindset
 
Started by M4ndoo, 04-20-2026, 05:21 PM
0 responses
134 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by M4ndoo, 04-19-2026, 05:54 PM
0 responses
68 views
0 likes
Last Post M4ndoo
by M4ndoo
 
Started by cmoran13, 04-16-2026, 01:02 PM
0 responses
118 views
0 likes
Last Post cmoran13  
Started by PaulMohn, 04-10-2026, 11:11 AM
0 responses
67 views
0 likes
Last Post PaulMohn  
Working...
X