When a strategy is running on 2 different instruments and the cashvalue reaches a defined target, is it possible to close all orders and open positions from code inside the strategy?
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Close All open Orders and Positions
Collapse
X
-
Close All open Orders and Positions
Hi,
When a strategy is running on 2 different instruments and the cashvalue reaches a defined target, is it possible to close all orders and open positions from code inside the strategy?Tags: None
-
daxtrading, it is definitely possible to close positions and cancel orders once a value reaches a certain target. To close positions, you can do an ExitLong() and ExitShort() inside each instrument's code block. Then you could also create some sort of flag to tell the strategy to not take anymore trades, like this:
For canceling the orders, you'll have to just run through each open order and call CancelOrder() for it.Code:if (cashvalue > target) { ExitLong(); ExitShort(); canTrade = false; } // and for your order submission stuff.... if (tradeConditions == true && canTrade == true) { // submit orders }
Please let me know if you have any other questions.AustinNinjaTrader Customer Service
-
-
I did use that but my position closed a secound after the open.Originally posted by NinjaTrader_Bertrand View Postdaxtrading, I'm not sure in which context you check it, it would be available in a strategy -
http://www.ninjatrader.com/support/h...countvalue.htm
This is the code I used:
if (GetAccountValue(AccountItem.CashValue) > 100500)
ExitLong();
ExitShort();
Comment
-
What is the code to close all orders/positions when account cash value + open profit > 125000Originally posted by NinjaTrader_Bertrand View PostThis would mean that the condition evaluated to 'true' then triggering the exit you coded in - you will need to keep in mind that this is the account cash value that does not include the open profit you would have.
Comment
-
Maarten, I would unfortunately not have a code snippet here for you - you would add the open Pnl for example to your account balance (GetProfitLoss()) - however the strategy would only know about it's own positions, it would not have access to any other strategies positions or manually entered ones.Originally posted by daxtrading View PostWhat is the code to close all orders/positions when account cash value + open profit > 125000
Comment
-
Ok Betrand, If I want it only to happen on the open position in one open strategy, can I do that and what code is needed?
Comment
-
I know how to exit on account balance and on GetProfitLoss seperately but not on a combination of these 2 conditions.
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
24 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
25 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|
||
|
Started by CaptainJack, 03-25-2026, 09:53 PM
|
0 responses
30 views
0 likes
|
Last Post
by CaptainJack
03-25-2026, 09:53 PM
|
||
|
Started by CaptainJack, 03-25-2026, 09:51 PM
|
0 responses
18 views
0 likes
|
Last Post
by CaptainJack
03-25-2026, 09:51 PM
|
||
|
Started by Mindset, 03-23-2026, 11:13 AM
|
0 responses
27 views
0 likes
|
Last Post
by Mindset
03-23-2026, 11:13 AM
|

Comment