NexusFi: Find Your Edge


Home Menu

 





Get executions trades from the indicator.


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Taddypole with 10 posts (1 thanks)
    2. looks_two shodson with 5 posts (1 thanks)
    3. looks_3 aquarius with 2 posts (1 thanks)
    4. looks_4 gregid with 1 posts (1 thanks)
      Best Posters
    1. looks_one gregid with 1 thanks per post
    2. looks_two aquarius with 0.5 thanks per post
    3. looks_3 shodson with 0.2 thanks per post
    4. looks_4 Taddypole with 0.1 thanks per post
    1. trending_up 5,968 views
    2. thumb_up 4 thanks given
    3. group 7 followers
    1. forum 21 posts
    2. attach_file 9 attachments




 
Search this Thread

Get executions trades from the indicator.

  #1 (permalink)
Sevas
Russia Ptz
 
Posts: 2 since Apr 2015
Thanks Given: 1
Thanks Received: 0

Hello,

Can't deal with how to get executions trades from the indicator. I can take them from db?

Thank you.

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
NexusFi Journal Challenge - April 2024
Feedback and Announcements
Exit Strategy
NinjaTrader
Deepmoney LLM
Elite Quantitative GenAI/LLM
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Get funded firms 2023/2024 - Any recommendations or word …
61 thanks
Funded Trader platforms
39 thanks
NexusFi site changelog and issues/problem reporting
26 thanks
The Program
18 thanks
Battlestations: Show us your trading desks!
18 thanks
  #3 (permalink)
 
gregid's Avatar
 gregid 
Wrocław, Poland
 
Experience: Intermediate
Platform: NinjaTrader, Racket
Trading: Ockham's razor
Posts: 650 since Aug 2009
Thanks Given: 320
Thanks Received: 623



Sevas View Post
Hello,

Can't deal with how to get executions trades from the indicator. I can take them from db?

Thank you.

Try getting the right account from the following collection (you will need "using NinjaTrader.Cbi;"):
 
Code
NinjaTrader.Cbi.Globals.Accounts
You should be able to identify the right one by the name

Once you have the "account" you can search in

 
Code
account.Positions
or
 
Code
account.Orders
or
 
Code
account.Executions
collections depending on what you want to achieve

Reply With Quote
Thanked by:
  #4 (permalink)
 Taddypole 
Phoenix, Arizona
 
Experience: Advanced
Platform: Ninja Trader
Trading: Oil
Posts: 54 since Jul 2009
Thanks Given: 1
Thanks Received: 7


gregid View Post
Try getting the right account from the following collection (you will need "using NinjaTrader.Cbi;"):
 
Code
NinjaTrader.Cbi.Globals.Accounts
You should be able to identify the right one by the name

Once you have the "account" you can search in

 
Code
account.Positions
or
 
Code
account.Orders
or
 
Code
account.Executions
collections depending on what you want to achieve

Once you have the collection, how do you extract information like the instrument traded, the position either long or short and the number of contracts? I have very little experience with collections.

thanks,
taddypole...

Reply With Quote
  #5 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


Taddypole View Post
Once you have the collection, how do you extract information like the instrument traded, the position either long or short and the number of contracts? I have very little experience with collections.

thanks,
taddypole...

For more info see this and this
 
Code
Print("Instrument = " + Instrument.MasterInstrument.Name);
Print("Am I long, short or flat? " + Position.MarketPosition.ToString());
Print("How many contracts am I holding? " + Position.Quantity);

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #6 (permalink)
 Taddypole 
Phoenix, Arizona
 
Experience: Advanced
Platform: Ninja Trader
Trading: Oil
Posts: 54 since Jul 2009
Thanks Given: 1
Thanks Received: 7

Thank you Shodson, that helped a lot.

Can you also show me where to find on the MSDN site references to the Collections used by NinjaTrader? There are several and I'm really not sure which one to focus on.


Also, in the attached figure, can you tell me how to find only the most recent entry for a specific instrument?

I really appreciate your help.

regards,
taddypole....

Attached Thumbnails
Click image for larger version

Name:	ExecutionCollection.jpg
Views:	183
Size:	194.1 KB
ID:	185422  
Reply With Quote
  #7 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


Taddypole View Post
Thank you Shodson, that helped a lot.

Can you also show me where to find on the MSDN site references to the Collections used by NinjaTrader? There are several and I'm really not sure which one to focus on.


Also, in the attached figure, can you tell me how to find only the most recent entry for a specific instrument?

I really appreciate your help.

regards,
taddypole....

The collections used by Ninjatrader are created by Ninjatrader, so you won't find them on the MSDN site. I don't know any central place that lists all of Ninjatraders collections. You just need to spend a lot of time in the "Ninjascript" section of the NT7 help guide.

NinjaTrader Version 7

As for finding the most recent execution, sorry, but you will probably have to use a foreach statement. The other possibility is a LINQ query but that's more complicated to explain how to do. I've never had a need to do what you are trying to do so I can't tell you off the top of my head but I could probably figure it out.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #8 (permalink)
 
aquarius's Avatar
 aquarius 
Monterrey, Mexico
 
Experience: Beginner
Platform: NinjaTrader
Trading: Treasuries
Posts: 22 since Nov 2012
Thanks Given: 5
Thanks Received: 69

You could also try listening to events being triggered:

 
Code
var accounts = NinjaTrader.Cbi.Globals.Accounts;
account = accounts.FindByName("Your account name");

account.PositionUpdate += account_PositionUpdate;
account.OrderStatus += account_OrderStatus;
account.Execution += account_Execution;
the execution event handler would look like:

 
Code
        private void account_Execution(object sender, NinjaTrader.Cbi.ExecutionUpdateEventArgs e)
        {
            Print(string.Format("Account_Execution event: Time: {0}, ExecutionId: {1}, Exchange: {2}, AccountName: {3}, OrderId: {4}, Instrument: {5}, Price: {6}, Quantity: {7}, MarketPosition: {8}, Operation: {9}, Rate: {10}, Sod: {11}, Multiplier: {12}, Error: {13}, NativeError: {14}", e.Time, e.ExecutionId, e.Exchange, e.Account.Name, e.OrderId, e.Instrument.FullName, e.Price, e.Quantity, e.MarketPosition, e.Operation, e.Rate, e.Sod, e.Multiplier, e.Error, e.NativeError));
        }
The account_Execution method will always have the latest event (execution) triggered.

Hope this helps

Reply With Quote
Thanked by:
  #9 (permalink)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709

Yeah, and you could keep track of the last trade as the event is fired with a class-level variable so you wouldn't have to search or foreach through any collections to find the last execution.

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #10 (permalink)
 Taddypole 
Phoenix, Arizona
 
Experience: Advanced
Platform: Ninja Trader
Trading: Oil
Posts: 54 since Jul 2009
Thanks Given: 1
Thanks Received: 7


thanks guys, I really appreciate this help.

Unfortunately I'm not a programmer and have some compile errors. I have some questions.

1. In which section of code do I put this new code?
2. Can you help me with the compile errors in the attachment?

thanks,
taddypole....

Attached Thumbnails
Click image for larger version

Name:	complieErrors.jpg
Views:	192
Size:	282.4 KB
ID:	185503  
Reply With Quote




Last Updated on July 23, 2015


© 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