View Full Version : dll problem
maxpi
07-25-2007, 09:56 AM
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.
NinjaTrader_Ray
07-25-2007, 09:59 AM
Make sure that you submit orders only if current bar is last bar.
maxpi
07-25-2007, 10:09 AM
oops, sorry. I've been doing Tradestation coding for years, still forget things like that.
maxpi
07-25-2007, 10:12 AM
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.
NinjaTrader_Ray
07-25-2007, 10:35 AM
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.
maxpi
07-25-2007, 11:18 AM
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...
NinjaTrader_Ray
07-25-2007, 11:32 AM
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.
maxpi
07-25-2007, 12:16 PM
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
07-25-2007, 12:32 PM
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
07-25-2007, 12:46 PM
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?
NinjaTrader_Ray
07-25-2007, 12:53 PM
Yes, NT supports tick by tick strategies on Volume bars.
maxpi
07-25-2007, 07:59 PM
It's nice working with professionals :)