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
Account Size - Safety Measure
Collapse
X
-
Account Size - Safety Measure
I'm looking to put a stop-gap safety net on my strategy. Something that will determine my account status, like if the account has lost 10% or something, flatten all trades (and make a martini). Could you point me in the right direction? Also, AccountSize() I see in the docs, but no info. Maybe that's what I need?Tags: None
-
imported post
We actually do not support account level properties in the NinjaScript layer at this time, however, I can see the value in what you ask. The code sample belows dives into our framework layer. This should do the trick but double check in testing on your live account. You will have to self calculate what the % loss value is against a user defined account cash balance. Mostbroker API's do not provide cash balance so its safer to enter the starting cash balance of your account when running the strategy. What I have provided below is conceptual.
Declare in variables section:
private bool safetyStop = false;
In OnBarUpdate()
// If flat and safety stop is hit, stop process strategy logic
if (safetyStop && Position.MarketPosition == MarketPosition.Flat)
return;
// In real-time only and the safety stop not yet hit
if (!Historical && !safetyStop)
{
// Check the account realized PnL and if the max loss exceeded
if (((AccountItem) Account.GetAccountItem(Cbi.AccountItemType.Realize dProftLoss, Cbi.Currency.Unknown)).Value < -100);
{
// Close any open position
safetyStop = true;
ExitLong();
ExitShort();
}
}
RayNinjaTrader Customer Service
-
Does this work in NinjaTrader 6.5 and was this an example from inside a NinjaScript? I am wondering why I could not use a similar method of ((AccountItem) Account.GetAccountItem(Cbi.AccountItemType.BuyingP ower, Cbi.Currency.Unknown)).Value to get BuyingPower in the same way?
Comment
-
@Ray, thanks for the reply. I understand this is not formally supported, however this information would be very useful to a number of people on these forums (just from the searches I have done) and it seems you have had to answer this inquiry many times. So if there was an unsupported way (via the Framework) to obtain this information that may work (but still of course not be formally supported) I think there are many that would appreciate it. I will reply to this thread if I am able to make it work myself, as of yet, no luck
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Waxavi, 04-19-2024, 02:10 AM
|
4 responses
54 views
0 likes
|
Last Post
by sonia0101
Today, 04:02 PM
|
||
Started by cmtjoancolmenero, Today, 03:58 PM
|
0 responses
5 views
0 likes
|
Last Post Today, 03:58 PM | ||
Net Change
by Segwin
Started by Segwin, 05-07-2018, 02:15 PM
|
11 responses
1,777 views
0 likes
|
Last Post
by aligator
Today, 03:54 PM
|
||
Started by trilliantrader, Today, 03:01 PM
|
1 response
8 views
0 likes
|
Last Post Today, 03:16 PM | ||
Started by geddyisodin, Today, 05:20 AM
|
6 responses
37 views
0 likes
|
Last Post
by geddyisodin
Today, 03:14 PM
|
Comment