Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using DLL NTmarket buy and sell in Tradestation Strategy

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Using DLL NTmarket buy and sell in Tradestation Strategy

    I am trying to create a strategy that will match account position in Tradestation with account at Interactive. The EasyLanguage verifies but I am not able to get execution in the SIM account...any help appreciated:

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

    #2
    Hello flygs,
    Thanks for your note.

    Please make sure the AT Interface is checked.
    • In Control Center menu bar goto File>AT Interface (should be checked).



    Also please make sure to use the correct account name.
    Code:
    if PositionsProvider1[0].Quantity =0 and NTMarketPosition("Sim101") =-1 then
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Unfortunately not working

      For some reason the startegy verifies in TS but is not taking any trades in NT Sim101

      Comment


        #4
        Hello flygs,
        Can you please send the log and trace files to support[AT]ninjatrader[DOT]com
        • You will find the log file on your PC in the (My) Documents > NinjaTrader 7 > Log folder.
        • The log file will be named "log.YYYYMMDD.txt"

        • You will find the trace file on your PC in the (My) Documents > NinjaTrader 7 > Trace folder.
        • The trace file will be named "trace.YYYYMMDD.txt"


        Please append Attn:Joydeep in the subject line of the email and give a reference of this thread in the body of the email.

        I look forward to assisting you further.
        JoydeepNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by algospoke, 04-17-2024, 06:40 PM
        6 responses
        48 views
        0 likes
        Last Post algospoke  
        Started by arvidvanstaey, Today, 02:19 PM
        4 responses
        11 views
        0 likes
        Last Post arvidvanstaey  
        Started by samish18, 04-17-2024, 08:57 AM
        16 responses
        61 views
        0 likes
        Last Post samish18  
        Started by jordanq2, Today, 03:10 PM
        2 responses
        9 views
        0 likes
        Last Post jordanq2  
        Started by traderqz, Today, 12:06 AM
        10 responses
        20 views
        0 likes
        Last Post traderqz  
        Working...
        X