Operations > Automated Trading > Automated Trading Interface (ATI) > TradeStation Integration > DLL Based Integration >

Sample Code

Print this Topic Previous pageReturn to chapter overviewNext page

The following EasyLanguage sample strategy "NTSample" is installed during the set up procedure. This sample is intended to demonstrate the use of NinjaTrader functions in EasyLanguage and NOT to illustrate any best practice or approach in function implementations.

 

Sample Code

{ 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;