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:
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
-
-
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
-
Originally 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
-
Originally posted by nailz420 View PostAre there any objections to using this to close any open positions?
if(Position.MarketPosition!=MarketPosition.Flat)
Position.Close();BertrandNinjaTrader Customer Service
Comment
-
Originally posted by daxtrading View PostWhat is the code to close all orders/positions when account cash value + open profit > 125000BertrandNinjaTrader Customer Service
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 GussJ, 03-04-2020, 03:11 PM
|
11 responses
3,227 views
0 likes
|
Last Post Today, 08:07 PM | ||
Started by andrewtrades, Today, 04:57 PM
|
1 response
13 views
0 likes
|
Last Post Today, 05:02 PM | ||
Started by chbruno, Today, 04:10 PM
|
0 responses
7 views
0 likes
|
Last Post
by chbruno
Today, 04:10 PM
|
||
Started by josh18955, 03-25-2023, 11:16 AM
|
6 responses
440 views
0 likes
|
Last Post
by Delerium
Today, 03:42 PM
|
||
Started by FAQtrader, Today, 03:35 PM
|
0 responses
12 views
0 likes
|
Last Post
by FAQtrader
Today, 03:35 PM
|
Comment