PDA

View Full Version : order execution


HelloHello
08-28-2007, 05:28 PM
int NTBuyLimit(string orderId, int quantity, double limitPrice)
Sends a buy limit order. A return value of 0 indicates success and -1 indicates an error. Success indicates success in submitting the command NOT that the order was successfully submitted.

1) I'm running this on tradestation.

Here's my code:
if condition1 then
begin
value1 = NTBuyLimit(ACCOUNT_NUM, 100, currentask + .05);
end;

Then... I notice that when there is a buy order tradestation does not recognize than an order was taken place. So in order to keep tradestation up to par with what is going on I write.

if condition1 then
begin
value1 = NTBuyLimit(ACCOUNT_NUM, 100, currentask + .05);
buy this bar 100 shares at currentask + .05 limit;
end;


So now tradestation thinks that it is in the trade and is able to look for exit conditions, however will I get a multiple order? I only want to buy 100 shares, but in order to keep tradestation knowing what the market position is I have to write the code "buy this bar 100 shares ..." in order to get tradestation on the same page as my market position.

So in the second code will get buy 100 or 200 shares?

HelloHello
08-28-2007, 06:53 PM
This is another example of what I'm getting at. Keeping TradeStation up to date with ninja trader

{ Copyright (c) 2005, NinjaTrader LLC ninjatrader@ninjatrader.com }
inputs: FastLength(9), SlowLength(18) ;
variables: FastAvg(0), SlowAvg(0), Success(0);
if LastBarOnChart and NTConnected(1) then begin
if NTMarketPosition("") = 0 then begin
{ place an order, if there is no position yet }
if AverageFC(Close, FastLength) > AverageFC(Close, SlowLength) then begin
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
end else begin
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
end;
end else begin
{ print some information on the current position and order }
Print("Position size: " + NumToStr(NTMarketPosition(""), 0));
Print("AvgEntryPrice: " + NumToStr(NTAvgEntryPrice(""), 2));
Print("OrderStatus: " + NTOrderStatus("MyOrderId"));
Print("Filled #: " + NumToStr(NTFilled("MyOrderId"), 0));
Print("AvgFillPrice: " + NumToStr(NTAvgFillPrice("MyOrderId"), 2));
end;
end;



Okay, imagine that this is your code. and you would like to exit in 10 bars. Tradestation has a function BarsSinceEntry. Because in the following code there is no code like, "buy this bar on close" trade station wouldn't know there is an order so it won't be keeping a running tab of the "bars since entry".

So in order to keep trade station up to date with NT, you'd have to write buy this bar on close; but if you have
if condition1 = true then
NTBuyMarket("MyOrderId", 1);
buy this bar on close;
end

now you have 2 orders.

I hope what I want to know is clear now

NinjaTrader_Dierk
08-29-2007, 12:17 AM
Unfortunately we can not provide support for TS EL code. Here are some generals hints:
- orders are placed in NT right away as you call the respective ATI methods
- there is no "protection" in place to prevent "redundant" order placement through ATI (unlike in NinjaScript)
- order are not canceled out next bar (unlike in NinjaScript)
- you probably should consider coding your strategy in NinjaScript