{ Copyright (c) 2005, NinjaTrader LLC [email protected] }
inputs: NTAccount("Sim101"),
string iAccounts1( "TSaccount" );
variables: Success(0);
method void PositionsProvider1_Updated( elsystem.Object sender, tsdata.trading.PositionUpdatedEventArgs args )
{ the Updated event hander method is called whenever a Position property changes }
begin
{ check to see if any position exists for the current symbol and plot position values }
if (PositionsProvider1.Count > 0) // and LastBarOnChart and NTConnected(1)
{ place an order, if there is no position yet } then
begin
{FLAT POSITION}
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =-1 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =-2 then
Success = NTBuyMarket("MyOrderId", 2); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 3); { buy 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =1 then
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =2 then
Success = NTSellMarket("MyOrderId", 2); { sell 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =0 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 3); { sell 3 unit at market, assign order id (optionally) }
{Long Position =1}
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =0 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =-1 then
Success = NTBuyMarket("MyOrderId", 2); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =-2 then
Success = NTBuyMarket("MyOrderId", 3); { buy 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 4); { buy 4 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =2 then
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =1 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 2); { sell 2 unit at market, assign order id (optionally) }
{Long Position =2}
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =0 then
Success = NTBuyMarket("MyOrderId", 2); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =1 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =-1 then
Success = NTBuyMarket("MyOrderId", 3); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =-2 then
Success = NTBuyMarket("MyOrderId", 4); { buy 4 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 5); { buy 5 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =2 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
{Long Position =3}
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =0 then
Success = NTBuyMarket("MyOrderId", 3); { buy 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =1 then
Success = NTBuyMarket("MyOrderId", 2); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =2 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =-1 then
Success = NTBuyMarket("MyOrderId", 4); { buy 4 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =-2 then
Success = NTBuyMarket("MyOrderId", 5); { buy 5 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 6); { buy 6 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =4 then
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =3 and NTMarketPosition("NTAccount") =5 then
Success = NTSellMarket("MyOrderId", 2); { sell 2 unit at market, assign order id (optionally) }
{Short Position=-1}
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =-2 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 2); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =0 then
Success = NTSellMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =1 then
Success = NTSellMarket("MyOrderId", 2); { buy 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =2 then
Success = NTSellMarket("MyOrderId", 3); { sell 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-1 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 4); { sell 1 unit at market, assign order id (optionally) }
{Short Position=-2}
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =-1 then
Success = NTSellMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =-3 then
Success = NTBuyMarket("MyOrderId", 1); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =0 then
Success = NTSellMarket("MyOrderId", 2); { buy 2 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =1 then
Success = NTSellMarket("MyOrderId", 3); { buy 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =2 then
Success = NTSellMarket("MyOrderId", 4); { sell 4 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-2 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 5); { sell 5 unit at market, assign order id (optionally) }
{Short Position=-3}
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =-1 then
Success = NTSellMarket("MyOrderId", 2); { buy 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =-2 then
Success = NTSellMarket("MyOrderId", 1); { sell 1 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =0 then
Success = NTSellMarket("MyOrderId", 3); { sell 3 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =1 then
Success = NTSellMarket("MyOrderId", 4); { sell 4 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =2 then
Success = NTSellMarket("MyOrderId", 5); { sell 5 unit at market, assign order id (optionally) }
if PositionsProvider1[0].Quantity =-3 and NTMarketPosition("NTAccount") =3 then
Success = NTSellMarket("MyOrderId", 6); { sell 6 unit at market, assign order id (optionally) }
End;
End;
Comment