NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 08-11-2012, 04:07 AM   #1
dalisdj
Member
 
Join Date: Oct 2011
Posts: 30
Thanks: 4
Thanked 1 time in 1 post
Default Understand of GetAccountValue and MasterInstrument

Hi guys,

I'm going to trade some of my automated strategies in realtime, buy I have to understrand some values of GetAccountValue first. So please let me understand what is the proper way to use it to be able to apply money management to my strategies to get things work.

I will use this simple example for better understand. Let's have account with size of $10 000 and let's go trade two futures instruments say FOO and BAR with same initial margins $1 000. Also let's have 2 strategies trading this instruments with actual state:
  • First strategy is in trade with 2 contracts over FOO with actual realized profit of +$500.
  • Second strategy is in trade with 1 contract over BAR with actual realized loss of -$200.

And the questions:
  • How can I get the value of initial margin for any instrument?
    GetAccountValue(AccountItem.InitialMargin) or MasterInstrument.Margin ??
  • How can I get available account value?
    In this case 10000 - 2*1000 - 1000 = $7 000
    Is it GetAccountValue(AccountItem.CashValue) or GetAccountValue(AccountItem.TotalCashBalance)
  • What exactly do I get from AccountItem.RealizedProfitLoss?
    Is it same global value for all strategies (in this case +$300), or value related to any single strategy so +$500 if I call from FOO strategy and -$200 if I call from BAR strategy ??
  • How can I get realized account value?
    In this case 10000 + 500 - 200 = $10 300
    Is it TotalCashBalance + RealizedProfitLoss ??
  • StopLoss for BAR strategy is 1%, what is the best way to restate this CalculationMode.Percentage value to CalculationMode.Price value??
    Is it 0.01 * Close[0] * MasterInstrument.PointValue ??
    Ex.: 0.01 * 2587 * 20 = $517.4
Hope you understand my questions.

Thanks
dalisdj is offline  
Reply With Quote
Old 08-12-2012, 10:54 AM   #2
NinjaTrader_AdamP
NinjaTrader Customer Service
 
NinjaTrader_AdamP's Avatar
 
Join Date: Aug 2011
Location: Denver, CO, USA
Posts: 2,895
Thanks: 241
Thanked 375 times in 365 posts
Default

dalisdj,

Unfortunately the MasterInstrument.Margin is unsupported code, however note that this MasterInstrument object is what is defined by your instrument manager.

GetAccountValue(AccountItem.CashValue) would work to get the account value.

Strategies are separate in all PnL calculation, so the RealizedProfitLoss is only from the strategy you are calling it from. You can read more about this here : http://www.ninjatrader.com/support/h..._account_p.htm

GetAccountValue(AccountItem.CashValue) would return the realized account value here, but please note it only works on realtime data.

Using CalculationMode.Price it would be the actual price of the stop loss you wanted, so something like : Close[0]*(1 - 0.01) should work.

Please let me know if I may assist further.
NinjaTrader_AdamP is offline  
Reply With Quote
Old 08-14-2012, 01:38 PM   #3
dalisdj
Member
 
Join Date: Oct 2011
Posts: 30
Thanks: 4
Thanked 1 time in 1 post
Default

Hi AdamP,

thanks for your support. It helped me in most issues, but I'm still not sure about available account money.

Let's say I have $10 000 account and active trades at total margin of $3 000. This means that I have available only maximum price of $7 000 to enter another trade, because size of $3 000 is blocked by my broker. So do I have to manage my strategies by my own to get available part of my account (in this case $7 000) if any position active?
dalisdj is offline  
Reply With Quote
Old 08-14-2012, 02:33 PM   #4
NinjaTrader_JC
NinjaTrader Customer Service
 
NinjaTrader_JC's Avatar
 
Join Date: Mar 2012
Location: Denver, CO
Posts: 1,199
Thanks: 135
Thanked 182 times in 181 posts
Default

Hello dalisdj,

That will depend on what your brokerage account supports. Some brokerage technology does not provide the buying power or the cash value.

http://www.ninjatrader.com/support/f...ead.php?t=5474

So if you call GetAccountValue() on a supported information you will not need to manually calculate it. Otherwise, you would have to calculate this or manage this separately.

Let us know if we can be of further assistance.
NinjaTrader_JC is offline  
Reply With Quote
Old 08-15-2012, 02:45 PM   #5
dalisdj
Member
 
Join Date: Oct 2011
Posts: 30
Thanks: 4
Thanked 1 time in 1 post
Default

Hi AdamP,

you still didn't answer to my question, but otherwise you let me know about really important issue of account value support. I didn't know about different support of each values and I see that my broker ZenFire support only two values, which should cause a problem in future. So thanks a lot you point me this.

I would like to generalize my questlion: What is the difference between CashValue and TotalCashBalance?
dalisdj is offline  
Reply With Quote
Old 08-15-2012, 02:54 PM   #6
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi dalisdj.

TotalCashBalance is not supported.

Possible supported values of this are:
AccountItem.BuyingPower
AccountItem.CashValue
AccountItem.RealizedProfitLoss

More info here for GetAccountValue()
http://www.ninjatrader.com/support/h...countvalue.htm
NinjaTrader_RyanM is offline  
Reply With Quote
Reply

Tags
getaccountvalue, masterinstrument

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
GetAccountValue guillembm Miscellaneous Support 6 12-11-2011 07:04 PM
MasterInstrument.Margin and MasterInstrument.Margin2 freewind General Programming 4 12-27-2010 06:42 AM
testing the GetAccountValue() method drolles Strategy Development 7 12-21-2010 09:41 AM
GetAccountValue on Sim101 MXASJ Version 7 Beta General Questions & Bug Reports 15 06-21-2010 09:42 AM
GetAccountValue ATI user Version 7 Beta General Questions & Bug Reports 5 10-25-2009 08:41 AM


All times are GMT -6. The time now is 09:50 AM.