NinjaTrader Support Forum  
X

Attention!

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


Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

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.

Reply
 
Thread Tools Display Modes
Old 07-25-2007, 09:56 AM   #1
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default dll problem

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.
maxpi is offline  
Reply With Quote
Old 07-25-2007, 09:59 AM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Make sure that you submit orders only if current bar is last bar.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-25-2007, 10:09 AM   #3
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default

oops, sorry. I've been doing Tradestation coding for years, still forget things like that.
maxpi is offline  
Reply With Quote
Old 07-25-2007, 10:12 AM   #4
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
maxpi is offline  
Reply With Quote
Old 07-25-2007, 10:35 AM   #5
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-25-2007, 11:18 AM   #6
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default

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.
maxpi is offline  
Reply With Quote
Old 07-25-2007, 11:32 AM   #7
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

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.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-25-2007, 12:16 PM   #8
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default

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...
maxpi is offline  
Reply With Quote
Old 07-25-2007, 12:32 PM   #9
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default

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..
maxpi is offline  
Reply With Quote
Old 07-25-2007, 12:46 PM   #10
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Default Can I trade from volume bars with NT

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?
maxpi is offline  
Reply With Quote
Old 07-25-2007, 12:53 PM   #11
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

Yes, NT supports tick by tick strategies on Volume bars.
NinjaTrader_Ray is offline  
Reply With Quote
Old 07-25-2007, 07:59 PM   #12
maxpi
Senior Member
 
Join Date: Jun 2007
Posts: 151
Thanks: 0
Thanked 0 times in 0 posts
Thumbs up Too cool..

It's nice working with professionals
maxpi is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 12:56 AM.