![]() |
|
|||||||
| Strategy Development Support for the development of custom automated trading strategies using NinjaScript. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Oct 2007
Posts: 30
Thanks: 0
Thanked 0 times in 0 posts
|
Hi, I'm looking to use the DLL with tradestation. I would like to be able to call a Ninja Function to get the number of contracts in the OrderID.
Is this possible? TIA AJNIN |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
What you can get is the filled amount of an order. Provided you store the original order quantity amount upon submission, you could get the difference.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Sep 2009
Location: Fernandina Beach, FL
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
Ray, could you please clarify, this seems complicated. So if I want to know how many contracts I'm LONG or SHORT in a position, I have to call NTFilled(OrderId) for every order?
For example, starting from Flat, I might BUY 10, then sell 5, and be stopped out on 2, giving a current position of 3; but to get this out of NTFilled(), am I going to have to know all of the possible standing orders and check them all on each bar? |
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
In your case you could do this with NTFilled. However you could instead use for example string NTOrderStatus(stringorderId); You can tell from this if your order is filled or part filled or working. http://www.ninjatrader.com/support/h...=order%2Bstate If it is PartFilled, then you would need to take some action and use NTFilled() to find out how many you where filled on and then take any action on your side you need to adjust for on your strategy side or wait until you have reached a status of filled which means that the entire order is filled.
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Sep 2009
Location: Fernandina Beach, FL
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
I never assume that the TradeStation and Ninja orders are in sync. For example, TradeStation might lose it's connection and restart. So, let's say you enter a trade in TradeStation and NinjaTrader, you lose the TradeStation connection which loses all your variables and TradeStation basically reloads the strategy when it comes back up, so you've lost all your variables such as OrderId. But consider that this might of been a complicated trade where I originally bought 10 (call that OrderId=Buy1), sold 5 (call that OrderId=Sell1), stopped out of 2 (call that OrderId=Stop1), rebought 4 (call that OrderId=Rebuy1), sold 2 again (call that OrderId=Sell2), and rebought 2 again (call that OrderId=Rebuy2), the question at this point is, the what is the current state of Ninja? You can easily get the MarketPosition as LONG, but how many contracts am I long? Without recreating the order sequence and knowing exactly what orders fired and filled, this seems impossible.
It seems that Ninja is missing the function that returns the number of open contracts. You have MarketPosition, what's the equivalent to CurrentContracts? If I knew how many contracts were open and what my MarketPosition was, I could just resume managing the order where I left off, whether I had 5, 7, or 10 contracts, when I hit my next target, I simply want to lay off a certain percentage of my original lot size. |
|
|
|
|
|
#6 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
You would not be able to do this type of sync on an account level. This would need to be manually synced. This is the same in our NinjaScript strategies the run inside of NinjaTrader. We do this because you may have multiple strategies running on the same instrument which would cause syncing issues if each one was trying to sync to the master account. Therefor when or if you need to restart the strategy. The strategy runs on historical data and figures out that it is for example should be 10 long. Either this will match what your account position is and you can continue on with no manual process needed. If there is a discrepancy you would then need to submit an order manually on your account for 10 contracts long if you where flat or whatever the difference is needed to sync what the trade station strategy expects to what your actual account position is for the strategy to continue to run smoothly and not get our of sync. This would need to be done with a NinjaScript strategy as well. An option you have in a NinjaScript strategy and you can do this also with a Trade Station strategy is to wait for market position to go back to flat before allowing the Trade Station strategy to start submitting orders. This way you can manage the exit manually and then when the strategy is flat it will then take the next signal for a trade and this would be one method available to you to insure that the strategy position and account position are in sync. However with this method you would need to insure that your account position is also flat when the strategy starts submitting orders. More general information on this for NinjaScript strategies that also applies to tradestation run strategies can be found here. Strategy Position vs. Account Position: http://www.ninjatrader-support2.com/...ead.php?t=4033 Let me know if I can be of further assistance.
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: Sep 2009
Location: Fernandina Beach, FL
Posts: 25
Thanks: 0
Thanked 0 times in 0 posts
|
I just discovered that NTMarketPosition returns the number of contracts you are LONG or SHORT, so if I'm LONG 15, it returns +15 and if I'm SHORT 15, it returns -15. This is exactly what I want. Is this an undocumented feature of NTMarketPosition?
|
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
douggreen,
That would indeed be the behavior of NTMarketPosition.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Accessing order fill price and quantity | NinjaTrader_Ray | Strategy Development | 2 | 01-03-2008 12:16 AM |
| Positions[0].Quantity return negative value when short? | Folls | Strategy Development | 2 | 10-23-2007 01:13 PM |
| Setting the order quantity in Strategy Wizard | scjohn | Strategy Development | 1 | 08-29-2007 07:23 AM |
| adjust contract quantity | ghale | Miscellaneous Support | 1 | 03-18-2006 04:13 AM |
| Scale (add to position) quantity default | trymph | Miscellaneous Support | 8 | 06-24-2005 02:36 AM |