Obtaining the Account in code and keeping reference to it thro re-connects etc - NinjaTrader Programming | futures io social day trading
futures io futures trading


Obtaining the Account in code and keeping reference to it thro re-connects etc
Updated: Views / Replies:1,298 / 6
Created: by Adamus Attachments:0

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 
Thread Tools Search this Thread
 

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

  #1 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

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

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.
Reply With Quote
 
  #2 (permalink)
Quick Summary
Quick Summary Post

How to write "unsupported" NinjaScript to get hold of all orders and positions on an account and check through them to make sure it's all running fine. Reversals seems to be really error-prone in NT7 - sometimes the new stop loss / target get cancelled as soon as they are submitted, leaving a position unprotected.

 
  #3 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: Mirus/Zen
Favorite Futures: Futures - bonds, currencies, index
 
Posts: 288 since Oct 2010
Thanks: 70 given, 267 received


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)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

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.
Reply With Quote
 
  #5 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: Mirus/Zen
Favorite Futures: Futures - bonds, currencies, index
 
Posts: 288 since Oct 2010
Thanks: 70 given, 267 received

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
The following user says Thank You to Xeno for this post:
 
  #6 (permalink)
Elite Member
London, UK
 
Futures Experience: Beginner
Platform: NinjaTrader, home-grown Java
Broker/Data: IB/IQFeed
Favorite Futures: EUR/USD
 
Adamus's Avatar
 
Posts: 1,085 since Dec 2010
Thanks: 470 given, 778 received

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.
Reply With Quote
 
  #7 (permalink)
Elite Member
UK
 
Futures Experience: Intermediate
Platform: Ninja
Broker/Data: Mirus/Zen
Favorite Futures: Futures - bonds, currencies, index
 
Posts: 288 since Oct 2010
Thanks: 70 given, 267 received

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

Reply



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

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Trading Metrics for journals/record keeping Big Mike Psychology and Money Management 928 September 10th, 2017 04:40 AM
paper account real account interactive brokers Mehdi IB Trader Workstation 15 January 6th, 2012 12:16 PM
Keeping it Simple Silver Dragon Trading Journals 26 September 19th, 2011 06:00 PM
Any stooge can make money in the market keeping it is what is difficult liquidcci Psychology and Money Management 2 August 18th, 2011 06:07 PM
Weekly Claims Turn Higher, Keeping Jobs Outlook Fragile Quick Summary News and Current Events 0 July 22nd, 2010 09:40 AM


All times are GMT -4. The time now is 11:13 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-16 in 0.14 seconds with 19 queries on phoenix via your IP 54.226.34.209