NexusFi: Find Your Edge


Home Menu

 





Obtaining the Account in code and keeping reference to it thro re-connects etc


Discussion in NinjaTrader

Updated
    1. trending_up 2,197 views
    2. thumb_up 1 thanks given
    3. group 1 followers
    1. forum 6 posts
    2. attach_file 0 attachments




 
Search this Thread

Obtaining the Account in code and keeping reference to it thro re-connects etc

  #1 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

I want to automate some sanity checking for NT7 which I currently do by eye (and occasionally get wrong, costing me serious money).

I have a strategy running on 20 forex pairs. The strategy enters a position and places a stop and a profit target bracket simultaneously.

Various things can go wrong so I'm going to try to build:

(a) an indicator for the Market Analyzer to display the nearest stop order

(b) a strategy whose sole purpose is to check every market for a position and check those with positions for the presence of a stop and a target order.

I have this, which the NT support team told me they can't help me with:

 
Code
// grab the Account:
foreach (Account account in Bars.MarketData.Connection.Accounts)
    if (account.Name == accountName)
        // do checks

 // then in indicator:
foreach (Order order in account.orders)
    // grab the stop orders for instrument

 // and in strategy:
 foreach (Position position in account.positions)
    // check it has orders associated with it

The "accountName" variable is a parameter I can set in the Parameters dialog box of the indicator or strategy, I found a NinjaTrader indicator that does some stuff in this area - BarTimer.cs - and I tried copying that as far as it went but I've had no joy.

The thing I can't figure out is which event should I use? It doesn't work in Initialize().

It looks like there are different events available in strategies that indicators don't have.

And of course I don't want to write something that's going to hog the CPU cycles just to do checks.

Generally speaking, maybe I'm barking up the wrong tree completely here - or perhaps there's a secret API documentation for NT7 somewhere that they wouldn't tell me?

Thanks in advance!

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
The space time continuum and the dynamics of a financial …
Emini and Emicro Index
My NT8 Volume Profile Split by Asian/Euro/Open
NinjaTrader
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Are there any eval firms that allow you to sink to your …
Traders Hideout
Futures True Range Report
The Elite Circle
 
  #3 (permalink)
 Xeno 
UK
 
Experience: Intermediate
Platform: Ninja
Broker: Mirus/Zen
Trading: Futures - bonds, currencies, index
Posts: 288 since Oct 2010
Thanks Given: 70
Thanks Received: 274


Hi Adamus, glad to see you joined.

I have a similar thing, not quite finished and tested. I run a strategy called MonitorLive which just checks account value changes and can email/text me. It also has an OnConnectionStatus to let me know if that goes down.

Regarding which event to use, what I do is run it against something that trades most of the time, like ES or 6E, and set it to a 1 min strategy. Then I put all the code in OnBarUpdate and it runs every minute (apart from when the market is closed which is 10pm for an hour, London time.)

Would that do it for you?

Reply With Quote
  #4 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

That sounds good. What is the actual if statement you use to trigger your alarm in onBarUpdate()?

That's definitely something I need. It isn't my primary aim, but I can see I'll need it to make sure I have a valid connection & therefore account etc.


PS you must be David? I would have put you in as my 'referrer' when I did the registration form but I didn't know your username - not sure what advantage it gives you but I'd be happy to do it in retrospect if I still can.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #5 (permalink)
 Xeno 
UK
 
Experience: Intermediate
Platform: Ninja
Broker: Mirus/Zen
Trading: Futures - bonds, currencies, index
Posts: 288 since Oct 2010
Thanks Given: 70
Thanks Received: 274

I just have an if statement that checks new account value against previous and sends me an email (or text if the difference is quite big!)

Something like

 
Code
newVal = GetAccountValue(AccountItem.CashValue)+GetAccountValue(AccountItem.InitialMargin);
 
newReal = GetAccountValue(AccountItem.RealizedProfitLoss);

if (Math.Abs(newVal-val) > 150 || Math.Abs(newReal-real) > 150) 
      notify() etc....
I'm not even sure the above works.

Reply With Quote
Thanked by:
  #6 (permalink)
 
Adamus's Avatar
 Adamus 
London, UK
 
Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker: IB/IQFeed
Trading: EUR/USD
Posts: 1,085 since Dec 2010
Thanks Given: 471
Thanks Received: 789

What are you not sure about? The notify() bit or the GetAccountValue stuff?

I think I can just play around with it on the simulation account, e.g. I can put something in the onConnectionStatus and then pull out the network cable.

Actually even with documentation, you still have to play around with the NinjaTrader API to find out what it really does.

You can discover what your enemy fears most by observing the means he uses to frighten you.
Follow me on Twitter Visit my NexusFi Trade Journal Started this thread Reply With Quote
  #7 (permalink)
 Xeno 
UK
 
Experience: Intermediate
Platform: Ninja
Broker: Mirus/Zen
Trading: Futures - bonds, currencies, index
Posts: 288 since Oct 2010
Thanks Given: 70
Thanks Received: 274

I mean I haven't tested it properly - the get account value bit.

By the way, the best way to test OnConnectionStatus is just to disconnect it using the control centre menu command. That fires the proc.

Reply With Quote




Last Updated on December 6, 2010


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts