Also, is there any way to detect if there are any open positions in ninjatrader outside of ninjatrader itself? I am creating an external application to send trading signals to certain clients, but it needs to be able to detect if I have any open positions. If I could do the former efficiently, then the latter isn't a necessity.
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
detection account position for a given instrument
Collapse
X
-
detection account position for a given instrument
Hey guys, I hope all is going well. Here is my situation: I need a strategy to be able to detect if any positions are open for a given account.. not JUST for the strategy. For example, if the account "Sim101" has a long trade open for the instrument "es 03-09", I would need to be able to detect that in the strategy.. even if that position was opened outside of the strategy being used. I would also need to be able to detect if the account is flat. Any advice? Thanks in advance.
Also, is there any way to detect if there are any open positions in ninjatrader outside of ninjatrader itself? I am creating an external application to send trading signals to certain clients, but it needs to be able to detect if I have any open positions. If I could do the former efficiently, then the latter isn't a necessity.Last edited by naifwonder; 01-16-2009, 02:58 AM.Tags: None
-
i should have been more specific, sorry about that..
what I meant was that the position would be opened in ninjatrader. However, it might be done so through a different strategy, or maybe through the dom. So what I should say is, I need to be able to find out about any positions opened in ninjatrader for a given account for a given instrument.
Comment
-
Hi Bertrand,
Thank you for your clarification. Do you work in NinjaTrader customer service dept? I have sent you a private message explaining my simple strategy.
Basically my strategy needs to re-balance my position based on the market situation and current existing position. It may need to buy a little more, sell a little more or flat the position. In order to calculate the current market value of my existing position, my strategy needs to know the ACCOUNT position of instruments instead of STATEGY position.
After searching, I found there is a similar one in FILE/DLL/COM inerface:
int MarketPosition(string instrument, string account)
Gets the market position for an instrument/account combination. Returns 0 for flat, negative value for short positive value for long
Will it return the account position of the instrument? Or it returns the strategy position and which strategy?
FYI, it is found in V6 help but not in V7 help. Is it deprecated?
Thanks
DanielLast edited by mydann; 07-20-2011, 08:26 PM.
Comment
-
NT 7 Market position
int MarketPosition(string instrument, string account)
Gets the market position for an instrument/account combination. Returns 0 for flat, negative value for short positive value for long.
Can you please give an example of the correct use of this function?
For example MarketPosition(ES 06-16, sim101)
I cannot get it working or get it to print to output. ... RegardsLast edited by elliot5; 06-02-2016, 07:38 AM.
Comment
-
Hello everington_f,
Thanks for your post.
The DLL functions are for use with an external program such as Tradestation or esignal (http://ninjatrader.com/support/helpG...terface_at.htm.
You can find examples of use here: http://ninjatrader.com/support/helpGuides/nt7/?
esignal_sample_code.htmPaul H.NinjaTrader Customer Service
Comment
-
NT 7 Market position
Ok I only use NT - then for an existing NT position - I can use
Positions[i].Account.Positions.Count >0
but it appears not to be instrument specific - if any position is open out of an array list the function counts it... how can I get account and instrument specific information for a position that is not a strategy position?
I have computer down time occasionally ... and need to be able to access the account position in code to manage them upon restart. (BTW I never understand why NT was not designed to be able to sync the strategy position to the account position.... Far more useful than the current situation. Regards
Comment
-
Hello everington_f,
Thanks for your reply.
You can access the account information in this way:
Code:foreach (Account acct in Cbi.Globals.Accounts) { if (acct.Positions != null) { PositionCollection positions = acct.Positions; foreach (Position pos in positions) { Print(pos.Account.Name + " " + pos.Instrument + " " + pos.MarketPosition + " " + pos.Quantity + " " + pos.AvgPrice); } }
Paul H.NinjaTrader Customer Service
Comment
-
pos. in conditional statement
Thankyou Paul - that prints to output beautifully.... But are the pos. values available for a conditional statement? This one doesnt compile...... perhaps you have a better example..
foreach (Account acct in Cbi.Globals.Accounts)
{
if (acct.Positions != null)
{
PositionCollection positions = acct.Positions;
foreach (Position pos in positions)
{
if (BarsInProgress == i
&& pos.Account.Name == sim101
&& pos.instrument == PFE Default
&& pos.MarketPosition == Short
&& GetCurrentAsk(i) <= MIN(Closes[i],5)[1])
{
EnterLong(i,voladjust, "Exit Short"+i);
}
}
}
}
Or can I use something along these lines?
if (BarsInProgress == i
&& Positions[i].Account.Positions.FindByAccountInstrument(sim101, PFE Default) == true)
perhaps (int MarketPosition(string instrument, string account) would work... but I need an example of instrument and account... cannot get the function to compile.
I simply need to be able to test in conditional setting for the presence of position in a specific instrument in an account. Regards and thxLast edited by elliot5; 06-03-2016, 07:46 AM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by RaygunWizzle, Yesterday, 08:52 PM
|
2 responses
10 views
0 likes
|
Last Post
by RaygunWizzle
Today, 02:26 PM
|
||
Started by carnitron, 03-25-2024, 01:59 PM
|
11 responses
50 views
0 likes
|
Last Post
by carnitron
Today, 02:18 PM
|
||
Started by Gerik, 12-21-2023, 08:20 AM
|
15 responses
202 views
0 likes
|
Last Post
by Mindset
Today, 02:06 PM
|
||
Started by visvabalaji, Today, 02:04 PM
|
0 responses
4 views
0 likes
|
Last Post
by visvabalaji
Today, 02:04 PM
|
||
Started by spottysallrite, Today, 11:31 AM
|
6 responses
15 views
0 likes
|
Last Post Today, 01:53 PM |
Comment