Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Auto close ATMs for AT orders.

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

    Auto close ATMs for AT orders.

    I have external code that sends in orders through the AT interface. It invokes an ATM, as a fail safe, strategy when it places a trade as follows:
    command=PLACE;
    account=Sim101;
    instrument=NQ 09-24;
    strategy = TV NQ;
    action=buy;qty=1;
    order_type=MARKET;
    tif=DAY;


    ​If I send a close order such as:
    command=CLOSEPOSITION;
    account=Sim101;
    strategy = TV NQ;
    instrument=NQ 09-24;"


    The position and the ATM close.
    The problem is that if NT doesn't receive the close and simply receives another opening order, in the opposite direction or not, the ATMs stay open.

    So, I'm trying to write a NT script that monitors the market position for the account and then closes any inappropriate ATM orders.
    The trouble I have is obtaining the various order IDs required for things like AtmStrategyClose(); In addition, most of these types of functions close the strategy.

    Thoughts?

    #2
    Hello mark0761,

    With the AT interface you need to be extremely specific on what you want to do, that is not like the strategy managed approach which will automatically close orders upon reversal. You would need to send the close position command to cancel the ATM.

    The OrderID's that you use in the AT interface are strictly for your external programs use, those are not going to be the actual order ids that the broker assigns. There is no way to extract the order ids that you see in the platform using the AT interface, you would need to track the orders based on the ID you supplied when submitting the orders.

    Comment


      #3
      So I send this command with an ATM id as follows:
      command=PLACE;
      account=SimTV;
      instrument=RTY 09-24;
      strategy = TV RTY;
      strategy_id=dogfoodshort;
      action=sell;
      qty=1;
      order_type=MARKET;
      tif=DAY;

      I then send:
      command=PLACE;
      account=SimTV;
      instrument=RTY 09-24;
      strategy = TV RTY;
      strategy_id=dogfoodlong;
      action=buy;
      qty=1;
      order_type=MARKET;
      tif=DAY;​

      The position is flat but the ATMs still exist.

      When I call "if(!weFlat) AtmStrategyClose("dogfoodlong");" from my strategy. I get the runtime error "'AtmStategyClose' method error: ATM strategy ID 'dogfoodlong' does not exist". What am I doing wrong?

      ​I also get the runtime error "'AtmStategyClose' method error: ATM strategy ID 'dogfoodshort' does not exist" after calling "if(!weFlat) AtmStrategyClose("dogfoodshort");"

      Comment


        #4
        Hello mark0761,

        Correct, you need to issue the CLOSEPOSITION command if you wanted to terminate the ATM. Automatic actions that happen in the platform when using NinjaScript or other tools are not going to happen with the AT interface, that is a simple command API so you would need to be specific when using that system and close the position to terminate the associated ATM.

        AtmStrategyClose is only intended for a NinjaScript strategy to use when it has submitted the ATM, that cannot be used in combination with the AT interface or manually placed orders.

        The AT interface is made with the intention that you will not be using any platform features and you have developed something outside of NinjaTrader that is in complete control, that is not intended to be used in addition to NinjaScript strategies. You would want to use one or the other and not both at the same time.

        Comment


          #5
          Fair enough. How can I achieve my objective of using a "hail Mary" stoploss for AT orders? My concern is that I place an order through the AT and then I lose the connection, so the close order is never received.

          Comment


            #6
            Hello mark0761,

            I am not sure what a hail mary stoploss is, could you provide detail on that?

            If you have a disconnect of the connection it wouldn't matter if you were using NinjaScript or the AT interface, the platform needs to be connected to issue commands that modify or submit orders. If you experience frequently connection losses an alternative approach would be to build what you want in NinjaScript and then run that on a VPS server with a reliable connection.

            Comment


              #7
              My trade closures are handled over the AT connection. The disconnect I was talking about was between the two systems, not NT losing it's connection. My concern is that during a position, communication is lost between the two systems and the closure order never arrives. The "hail Mary" stop loss is an ATM strategy that will handle the closure in the event of a loss of comm.

              The Hail Mary reference:

              Comment


                #8
                Hello mark0761,

                In that case because you are using two seperate systems that would fall on you to make sure that connection remains open and the two systems can communicate. There is nothing specific that I could suggest for that situation as you built the overall system that is using the AT interface. As long as NinjaTrader stays open and connected and your software does the same and can communicate then that can work in theory. I would suggest to avoid using two seperate systems if that is a concern and run your software locally with NinjaTrader, that avoids any disconnect situation. If an order never arrives then that is exactly what will happen, NinjaTrader has no advanced knowledge of that order to do anything.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by NullPointStrategies, Today, 05:17 AM
                0 responses
                20 views
                0 likes
                Last Post NullPointStrategies  
                Started by argusthome, 03-08-2026, 10:06 AM
                0 responses
                119 views
                0 likes
                Last Post argusthome  
                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                0 responses
                63 views
                0 likes
                Last Post NabilKhattabi  
                Started by Deep42, 03-06-2026, 12:28 AM
                0 responses
                41 views
                0 likes
                Last Post Deep42
                by Deep42
                 
                Started by TheRealMorford, 03-05-2026, 06:15 PM
                0 responses
                45 views
                0 likes
                Last Post TheRealMorford  
                Working...
                X