![]() |
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
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
I'm running the following code in Tradestation 8.2:
inputs: size(1); variables: marktpos(0), OrderID (""); marktpos =NTMarketPosition("AB1234"); if marktpos=0 then begin OrderID ="EnterShort"; value1 =NTSellMarket(OrderId,size); end; if marktpos=1 then begin OrderID ="EnterShort"; value1 =NTSellMarket(OrderId,2); end; if marktpos=-1 then begin OrderID ="ReverseShort"; value1 =NTBuyMarket(OrderId,2); end; I have the indicator set to update at end of bar, not every tick. It is supposed to just test the interface by entering short first then reversing at the close of every bar. When I deploy it, it sends off a zillion orders about a second apart, all short with quantity =1. I wind up with lots of contracts in my simulation account and programs not responding.. I have another indicator plotting marketposition and it never gets the position, it reads "0" all the time so it appears that the above code never updates the marketpostion and it also sends off orders intrabar when it should only send them at the end of the bar. |
|
|
|
|
|
#2 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Make sure that you submit orders only if current bar is last bar.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
oops, sorry. I've been doing Tradestation coding for years, still forget things like that.
|
|
|
|
|
|
#4 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
The code is now:
inputs: size(1); variables: marktpos(0), OrderID (""); marktpos =NTMarketPosition("DU1087"); if lastbaronchart then begin if marktpos=0 then begin OrderID ="EnterLong"; value1 =NTSellMarket(OrderId,size); end; if marktpos=1 then begin OrderID ="EnterShort"; value1 =NTSellMarket(OrderId,2); end; if marktpos=-1 then begin OrderID ="ReverseShort"; value1 =NTBuyMarket(OrderId,2); end; end; Plot1(marktpos,"Position",green); Now, at the end of every bar it sends off a market order, size =1; It does not seem to ever know that the marketposition is other than flat. |
|
|
|
|
|
#5 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Positions are only reported if the position was initiated through the ATI.
Restart NT and try again. I would also point out our sample code (in HelpGuide and should also be NTSample strategy in TS), run that and modify from there as a learning approach.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
I flattened the position with IB and restarted NT and had same problem, restarted whole computer and had the same problem. Here is the code as currently running:
inputs: size(1); variables: marktpos(0), OrderID (""); marktpos =NTMarketPosition("AB1234"); if lastbaronchart then begin if marktpos=0 then begin OrderID ="EnterLong"; value1 =NTSellMarket(OrderId,size); end; if marktpos=1 then begin OrderID ="EnterShort"; value1 =NTSellMarket(OrderId,2); end; if marktpos=-1 then begin OrderID ="ReverseShort"; value1 =NTBuyMarket(OrderId,2); end; end; Plot1(marktpos,"Position",green); It just keeps on selling one contract and never seems to get the idea that the marketposition is anything other than zero. In TWS and in NT Control Center it is reported that the marketposition is short and both of those update promptly with every bar's new order.... I don't see where I am doing anything differently than the NT sample strategy except I am running an indicator to call the NTdll code...
Last edited by maxpi; 07-25-2007 at 11:31 AM.
|
|
|
|
|
|
#7 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Flatten IB, restart NT, run the NTSample strategy for verification that it will work. If not, please let me know otherwise use this template as a starting point.
Thanks in advance.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
I flattened with IB, restarted Control Center, connected to IB, the AT interface is enabled. I installed the Sample Strategy and get no orders, I installed the Sample Indicator and also get no orders... This is running on volume bars in TS I will switch it to minute bars, TS has problems with volume bars come to think of it, I thought it was all related to intrabar trading but maybe not...
OK, on minute bars end of bar, it works, on volume bars it does not work end of bar. I'll try it in Multicharts... that is more my focus nowadays than Tradestation... |
|
|
|
|
|
#9 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
The NTSample Strategy does not send any orders from Multicharts at all, not on 30 minute charts or volulme bars. I know you don't support Multicharts but it's a just a side note..
|
|
|
|
|
|
#10 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
I'm working to find a platform that will autotrade from volume bars, intrabar, preferrably from an indicator. Will NinjaTrader do that for me, assuming I can write the C# code?
|
|
|
|
|
|
#11 |
|
Administrator
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
|
Yes, NT supports tick by tick strategies on Volume bars.
Ray
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Senior Member
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
|
It's nice working with professionals
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|