Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATI & ATMs

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

    ATI & ATMs

    Hi. Sorry if this is a stupid question or if it's been asked before, I'm new to NT7.

    I'm using the Advanced Trading Interface to place stock orders and attach them to pre-defined ATM strategies (templates). Sometimes the initial entry order is only partially filled and the ATM strategy begins to create stop/target orders for those partial positions. Sometimes those orders are for just one or two shares, creating upwards of what appears to be dozens of open orders. Given the brokerage costs associated with all those it would destroy any profit margin. Also, after multiple partial fills without the stop/targets being executed the ATM doesn't appear to consolidate those open orders to accommodate the entire position, instead it seems to leave them standing.

    My first question is: am I seeing this right? Or, would the ATM have eventually sorted all those orders out after the initial entry order was completely filled or killed?

    My second questions is: assuming what I saw is correct, is there a way to force NinjaTrader to do all-or-none (AON) entry orders? There doesn't seem to be a way to do this through the ATI "COMMAND" function, but maybe via some option in NT?

    My third question: is there a way to force ATM orders to wait or consolidate on all the partial fills before setting profit/stop orders?
    Last edited by HumbleMe; 04-14-2014, 10:26 AM.

    #2
    Hello HumbleMe,

    Thank you for your note.

    While this can be controlled for Automated NinjaScript Strategies (through the use of the "Stop & target submission" property) it is unfortunately not possible through the File Interface.

    Comment


      #3
      So you're saying that an ATM strategy can open dozens of stop/target orders for a single entry request then just leave them like that? I don't get this, why not consolidate the target orders after the entry is filled?

      Is there a way to automatically dynamically adjust the stocks NT7 NinjaScript trades (internally or externally) throughout the day?
      Last edited by HumbleMe; 04-14-2014, 10:47 AM.

      Comment


        #4
        Hello HumbleMe,

        Thank you for your response.

        ATM Strategies will be submitted for each fill of the order. If using the File Interface each fill is as if manually entered at that moment for that quantity. There is no method around this unless developing your strategy natively in NinjaTrader through NinjaScript as NinjaTrader can manage the ATM Strategies PerEntryExecution or ByStrategyPosition.

        The only method to adjust the instruments traded by an Automated NinjaScript Strategy would be by disabling that strategy that is running on the instrument you no longer want the strategy to run on.

        Comment


          #5
          Originally posted by NinjaTrader_PatrickH View Post
          The only method to adjust the instruments traded by an Automated NinjaScript Strategy would be by disabling that strategy that is running on the instrument you no longer want the strategy to run on.
          Thanks for your help, Patrick. A question on the above quote: can this be done programmatically? Could I, say, via an external application, enable/disable NinjaScript strategies?

          The problem I have is: I need to monitor some 6500+ stocks for EOD signals and enter, just the top two signaled stocks, near their day's close. My understanding is that this is outside the scope of reasonable handling for NinjaScript or the Market Analyzer, as it would take a long time to update price and signal data on 6500+ stocks.

          Er forgo, doing the monitoring externally then using the ATI DLL to enter the positions and the ATM to manage their exits seemed like an ideal solution. The only caveat, as mentioned in above posts, is the dozens of target/stop orders for partial fills.

          I'm guessing it's not possible to attach an ATM to a strategy/order after it's reached some fill state?

          Could I place an entry order unattached to a strategy, monitor it until it reaches some fill state, then place an exit order (profit target), potentially after the market has closed for the day? If an order is placed via the ATI after the market close is it still sent to the brokerage at night for execution in the morning?
          Last edited by HumbleMe; 04-14-2014, 10:42 PM.

          Comment


            #6
            Hello HumbleMe,

            Thank you for your response.

            There would be no supported method of disabling or enabling a strategy, and I am unaware of any unsupported methods to do this through the .DLL interface.

            As you guessed it would not be possible to submit an ATM Strategy to a position after it was completely filled. The ATM Strategy would need to be part of the original submission. You can always manage the exits through your own logic rather than using the ATM Strategies, but this would require further coding.
            If an order is placed via the ATI after the market close is it still sent to the brokerage at night for execution in the morning?
            This will depend on the broker and if they support orders after hours. If they do, then yes it will work as expected. Please clarify with your broker on orders submitted after hours.

            Comment


              #7
              If somebody else should have this problem, I wrote this bit of code. It basically just changes the first order to the strategy's position size then cancels the rest.

              Some caveats:
              - When you cancel a Target order in an OCO the associated Stop order is also canceled, but sometimes there seems to be a lag/lingering effect. i.e. More than one Stop after canceling all but one Target exists for the strategy.
              - The Stop position doesn't seem to update properly for me. It would occasionally add a few shares but never the entire strategy position that was passed, like the Target order would.
              - Leaving the Stop price at 0 (which the documentation says means the price will be "unchanged") would produce an OIF error "stop price parameter can't be zero" in the logs. I don't need the stops so it's not a problem for me, but it might be something to look at.

              Edit: If you include both the position and stop price the Stop order seems to update properly for me.

              Code:
                  Dim nc as New NinjaTrader.Client.Client()
              
                  Private Function manageStrategies() As errorResponses
              
                      If nc.Connected(0) <> 0 Then
                          debug("manageStrategies() NT connect unsuccessful.")
                          Return errorResponses.NT_CONNECTION
                      End If
              
                      Dim strategies() As String = nc.Strategies(default_account).Split("|")
              
                      If strategies IsNot Nothing AndAlso strategies.Length > 0 Then
              
                          For i As Integer = 0 To strategies.Length - 1
              
                              If strategies(i) = "" Then Continue For ' Rogue strategies
              
                              Dim position As Integer = nc.StrategyPosition(strategies(i))
              
                              Dim _targets() As String = nc.TargetOrders(strategies(i)).Split("|")
              
                              If _targets IsNot Nothing Then
              
                                  Dim targets As New ArrayList
              
                                  For j As Integer = 0 To _targets.Length - 1
                                      If _targets(j) = "" Then Continue For
                                      Select Case nc.OrderStatus(_targets(j))
                                          Case "Cancelled", "Filled" : Exit Select
                                          Case Else : targets.Add(_targets(j))
                                      End Select
                                  Next
              
                                  _targets = Nothing
              
                                  If targets.Count = 0 Then
              
                                      ' This is true for canceled or dead strategies.
              
                                      'debug("manageStrategies() no active target orders for strategy: " & strategies(i))
              
                                  ElseIf targets.Count = 1 Then
              
                                      ' Where we want to be, but no real way of checking if the order position = fill position
              
                                  ElseIf targets.Count > 1 Then
              
                                      If nc.Command("CHANGE", "", "", "", position, "", 0, 0, "", "", targets(0), "", "") <> 0 Then
                                          debug("manageStrategies() CHANGE Target(0) command didn't return zero: " & strategies(i) & vbTab & targets(0))
                                      Else
                                          For j As Integer = 1 To targets.Count - 1
                                              If nc.Command("CANCEL", "", "", "", 0, "", 0, 0, "", "", targets(j), "", "") <> 0 Then
                                                  debug("manageStrategies() CANCEL targets command didn't return zero: " & strategies(i) & vbTab & targets(j))
                                              End If
                                          Next
                                      End If
              
              
                                      Dim _stops() As String = nc.StopOrders(strategies(i)).Split("|")
              
                                      If _stops IsNot Nothing Then
              
                                          Dim stops As New ArrayList
              
                                          For j As Integer = 0 To _stops.Length - 1
                                              If _stops(j) = "" Then Continue For
                                              Select Case nc.OrderStatus(_stops(j))
                                                  Case "Cancelled", "Filled" : Exit Select
                                                  Case Else : stops.Add(_stops(j))
                                              End Select
                                          Next
              
                                          _stops = Nothing
              
                                          If stops.Count = 0 Then
                                              debug("manageStrategies() no active stop orders for strategy: " & strategies(i))
                                              'ElseIf stops.Count > 1 Then
                                              'Happens for some reason.  Maybe because they're not canceled quick enough?
                                              'debug("manageStrategies() more than one stop order for strategy: " & strategies(i))
                                          Else
                                              If nc.OrderStatus(stops(0)) = "Accepted" Then
                                                  If nc.Command("CHANGE", "", "", "", position, "", 0, 0.01, "", "", stops(0), "", "") <> 0 Then
                                                      debug("manageStrategies() CHANGE Stop(0) command didn't return zero: " & strategies(i) & vbTab & stops(0))
                                                  End If
                                              End If
                                          End If
              
                                      Else
              
                                          debug("manageStrategies() Stops is Nothing for strategy: " & strategies(i))
              
                                      End If
              
                                  End If
              
                              Else
              
                                  debug("manageStrategies() Targets is Nothing for strategy: " & strategies(i))
              
                              End If
              
              
                          Next
              
                      End If
              
                      Return errorResponses.SUCCESS
              
                  End Function
              Last edited by HumbleMe; 04-18-2014, 07:24 AM.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              65 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              41 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              23 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              26 views
              0 likes
              Last Post TheRealMorford  
              Started by Mindset, 02-28-2026, 06:16 AM
              0 responses
              52 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Working...
              X