ninjatrader: strategy accessing of accounts info - NinjaTrader | futures io social day trading
futures io futures trading


ninjatrader: strategy accessing of accounts info
Updated: Views / Replies:438 / 4
Created: by pxp333 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
 

ninjatrader: strategy accessing of accounts info

  #1 (permalink)
Trading Apprentice
Parlin NJ/USA
 
Futures Experience: Advanced
Platform: Ninjatrader
Favorite Futures: NQ
 
Posts: 7 since Mar 2015
Thanks: 0 given, 0 received

ninjatrader: strategy accessing of accounts info

Hi All,

I am using this snippet of code in my ninja 7 strategy within OnBarUpdate():

if (!Historical)
{rej.Set(0);
foreach (Account acct in Cbi.Globals.Accounts)
{PositionCollection positions=acct.Positions;
foreach (Position pos in positions)
if (pos.MarketPosition.ToString()=="Long")
{rej.Set(1);}
else if (pos.MarketPosition.ToString()=="Short")
{rej.Set(-1);}}}

where rej is an IntSeries

Ninja apparently does not support this type of coding, but it works with ninjascript.

My question is the following:

If I have only 1 account and I am trading only 1 instrument then the above snippet works for me.

But I would like for it to be more directed so that I can direct the code to access only a specific account for example Sim101 and within that account only a specific instrument for example ES futures.

What the code does is to allow the strategy know the current position of my actual trading account upon each bar update i.e. long=1, short=-1 or flat=0.

Since there is no NT documentation regarding accessing Accounts and this above coding I don't know how to modify the above code so as to not use foreach{} but to instead specify the account and instrument to query for the type of position currently being held.

Any assistance regarding this would be greatly appreciated.

Thanks

Reply With Quote
 
  #2 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received

I haven't tested it but try using Linq (using System.Linq) and do something like:

 
Code
foreach (Position pos in from Account acct in Cbi.Globals.Accounts where acct.Name == "Sim101" select acct.Positions into positions from Position pos in positions select pos)
{
    if (pos.MarketPosition.ToString() == "Long")
    {
       rej.Set(1);
    }
    else if (pos.MarketPosition.ToString() == "Short")
    {
        rej.Set(-1);
    }
}

Reply With Quote
 
  #3 (permalink)
Trading Apprentice
Parlin NJ/USA
 
Futures Experience: Advanced
Platform: Ninjatrader
Favorite Futures: NQ
 
Posts: 7 since Mar 2015
Thanks: 0 given, 0 received


Hi gregid,

I appreciate the reply. I got your code to compile but I didn't test it yet because I also need to discriminate the instrument for example "ES 06-15 Globex".

Would you be able to incorporate this into your code?

Also your code ideas got my brain going again and I was able to modify my code as follows to get it to work.


if (!Historical)
{rej.Set(0);
foreach (Account acct in Cbi.Globals.Accounts)
{PositionCollection positions=acct.Positions;
foreach (Position pos in positions)
if ((pos.Account.Name.ToString()=="Sim101")&&(pos.Instrument.ToString()=="ES 06-15 Globex"))
{if (pos.MarketPosition.ToString()=="Long")
{rej.Set(1);}
else if (pos.MarketPosition.ToString()=="Short")
{rej.Set(-1);}}}}

I forgot that foreach loops so it can parse the PositionCollection generated by the code. So I just added the higher if statement

if ((pos.Account.Name.ToString()=="Sim101")&&(pos.Instrument.ToString()=="ES 06-15 Globex")){}

I have seen on the web that others were trying to do similar accounts info queries from their strategies so us posting these codings here maybe can also help out.

Thanks

Reply With Quote
 
  #4 (permalink)
Elite Member
Wrocław, Poland
 
Futures Experience: Intermediate
Platform: NinjaTrader, Racket
Favorite Futures: Ockham's razor
 
gregid's Avatar
 
Posts: 651 since Aug 2009
Thanks: 321 given, 605 received

This is going to be completely dry coding on my side - I don't have any code editor at hand - so don't hold me accountable for this , but I would try:

 
Code
foreach (Position pos in from Account acct in Cbi.Globals.Accounts where acct.Name == "Sim101" select acct.Positions into positions from Position pos in positions where pos.Instrument=="ES 06-15 Globex" select pos)
{
    if (pos.MarketPosition.ToString() == "Long")
    {
       rej.Set(1);
    }
    else if (pos.MarketPosition.ToString() == "Short")
    {
        rej.Set(-1);
    }
}

Reply With Quote
 
  #5 (permalink)
Trading Apprentice
Parlin NJ/USA
 
Futures Experience: Advanced
Platform: Ninjatrader
Favorite Futures: NQ
 
Posts: 7 since Mar 2015
Thanks: 0 given, 0 received

Hi gregid,


I needed to append .ToString() to the pos.Instrument== in your modified statement for it to compile.

I tested it and it works.

Thanks again!

Reply With Quote

Reply



futures io > > > > ninjatrader: strategy accessing of accounts info

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
NinjaTrader + Interactive Brokers (multiple accounts) dtrade88 NinjaTrader 12 January 18th, 2016 06:03 PM
One Ninjatrader strategy running on multiple IB accounts zuska NinjaTrader 2 October 15th, 2014 09:50 AM
Accessing Daily Data for Intraday Strategy matthaius EasyLanguage Programming 4 August 1st, 2013 03:16 AM
Accessing Rectangle Bounds within a strategy Xav1029 NinjaTrader Programming 7 January 18th, 2013 04:38 PM
Accessing a chart from a strategy richtobey NinjaTrader Programming 3 December 31st, 2010 05:07 AM


All times are GMT -4. The time now is 02:49 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-12 in 0.08 seconds with 19 queries on phoenix via your IP 54.90.207.75