![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
Hi,
Can I get confirmation from someone on when "Performance.AllTrades" is set...? If I've just had a position flattened, is that trade already written into by the time I go into OnPositionUpdate? Here's the problem. I need to know the price I exited at... and I've been using Performance.AllTrades to figure out that price (scanning through looking for matching instrument name.) I'm doing this in OnPositionUpdate instead of OnExecution/OnOrderUpdate because of reports those might be wrong on IB. This has worked really well in the past, but just threw me a weird exception suggesting Performance.AllTrades was empty at the time when it executed. I'm printing line numbers, so I know it happened on this line: Quote:
Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.Collections.CollectionBase.System.Collectio ns.IList.get_Item(Int32 index) at NinjaTrader.Strategy.TradeCollection.get_Item(Int3 2 index) at NinjaTrader.Strategy.ProtectDownMulti.OnPositionUp date(IPosition position) in c:\Documents and Settings\Chon\My Documents\NinjaTrader 6.5\bin\Custom\Strategy\ProtectDownMulti.cs:line 942 System.Collections.IList.get_Item Line: 0 Column: 0 |
|
|
|
|
|
|
#2 |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
I might try to get away from using Performance.AllTrades entirely.
So, a related question is... inside OnPositionUpdate, is my IOrder object (for the latest order) already filled out with updated details on the exit execution? Can I pull price information from there? Just want to avoid a possible race condition. |
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
heech,
OnPositionUpdate() will be the last one in the sequence meaning you can use Performance or IOrder and they will be up to date at that moment in time. As far as your exception goes. Please check your for-statement again. You can easily go in with a -1 index as the first run through on that statement.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 | |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
Quote:
I'll modify the code to use IOrder just in case. |
|
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
heech,
You have no checks there to prevent you from running the for-loop when Performance.AllTrades.Count is 0. This is why you are getting the index out of range.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
My point is there's no reason AllTrades.Count can be 0, because this code is only getting turned on if there was a prior long order (which is now going flat). So, that's why I asked about the sequence of Performance versus OnOrderUpdate.
|
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Aside from .Count then please also reconsider your index++ logic. You should be going index--.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
|
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Dec 2006
Location: Seattle, Washington, USA
Posts: 150
Thanks: 0
Thanked 0 times in 0 posts
|
|
|
|
|
|
|
#10 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
You can find the list in the Index page of the Help Guide. Just scroll down to the O section. Unfortunately there is no article about the sequence. Generally its OnOrderUpdate->OnExecution->OnPosition.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#11 | |
|
Senior Member
Join Date: Nov 2008
Posts: 576
Thanks: 0
Thanked 1 time in 1 post
|
Quote:
Can you tell me the sequence order between OnExecution, and either Performance or IOrder...? (Is Performance updated by the time OnExecution is called..?) I'm changing my logic around slightly again, and I find it necessary to deal with the above. Thanks. |
|
|
|
|
|
|
#12 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
Yes it will be updated.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is trade available within OnPositionUpdate? | heech | Strategy Development | 2 | 12-04-2008 08:01 AM |
| OnPositionUpdate problem | kekkis | Strategy Development | 5 | 11-21-2008 07:02 AM |
| Performance.AllTrades index ? | michaelbb | Strategy Development | 1 | 06-17-2008 01:58 AM |
| Bug in Performance.AllTrades? | trader_rick | Automated Trading | 4 | 05-16-2008 07:09 PM |
| OnPositionUpdate Questions | OnePutt | General Programming | 1 | 11-30-2007 01:09 PM |