Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ninjascript atm

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

    ninjascript atm

    Hi,
    Within a ninjascript stratetgy which calls an ATM strategy, what method would one use to cancel an order which hasn't filled within x bars?
    thanks,
    David

    #2
    Hello David,

    AtmStrategyCancelEntryOrder()

    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      I inserted the code as-is and nothing happens. Bars continue to form, and the order sits unfilled.
      Perhaps one of you could write it into the SampleAtmStrategy so we can see an example which works?
      thanks,
      David
      Last edited by trader3000a; 11-04-2023, 09:12 AM.

      Comment


        #4
        Hello David,

        May I confirm you are providing the orderId string of the order (which was also supplied to AtmStrategyCreate())?

        Attached is a simple example.
        Attached Files
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Hi Chelsea,
          Thanks for your reply. Your example cancels the order after 1 bar as expected. How do I properly set the # of bars to wait? I tried modifying your example with the code from the reference library and now the order does not cancel:

          else if (isAtmStrategyCreated)
          {
          //////////////////////////////////
          string[] entryOrder = GetAtmStrategyEntryOrderStatus("orderId");
          if (entryOrder.Length > 0 && entryOrder[2] == "Working")
          {
          //////////////////////////////////
          AtmStrategyCancelEntryOrder(orderId);
          atmStrategyId = string.Empty;
          orderId = string.Empty;
          }
          }

          David​

          Comment


            #6
            Hello David,

            You could use an integer as a counter incremented on each new bar to make a condition that triggers after a certain number of bars.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hi Chelsea,
              This is doing the job:

              else if (isAtmStrategyCreated)
              {
              string[] status = GetAtmStrategyEntryOrderStatus(orderId);
              barCount++;

              if (barCount == 2 && status[2] != "Filled")
              {
              AtmStrategyCancelEntryOrder(orderId);
              atmStrategyId = string.Empty;
              orderId = string.Empty;
              barCount = 0;
              }
              }
              ​

              However, once the order is Filled and status is "Filled", I receive the error:
              _____________________________
              11/7/2023 7:02:47 AM
              The entry order average fill price is: 0
              The entry order filled amount is: 0
              The entry order order state is: Working
              barCount: 1
              _____________________________
              11/7/2023 7:02:56 AM
              The entry order average fill price is: 15195.5
              The entry order filled amount is: 5
              The entry order order state is: Filled
              barCount: 2
              'GetAtmStrategyEntryOrderStatus' method error: Missing order ID parameter
              'GetAtmStrategyEntryOrderStatus' method error: Missing order ID parameter
              'GetAtmStrategyEntryOrderStatus' method error: Missing order ID parameter
              'GetAtmStrategyEntryOrderStatus' method error: Missing order ID parameter
              'GetAtmStrategyEntryOrderStatus' method error: Missing order ID parameter

              I'm wondering why, if I'm only emptying the order Id string if the status != "Filled", I'm losing the order Id after being filled.

              thanks,
              David
              Last edited by trader3000a; 11-07-2023, 06:10 AM.

              Comment


                #8
                Hello David,

                "I'm wondering why, if I'm only emptying the order Id string if the status != "Filled", I'm losing the order Id after being filled."

                You may have other code in the script where orderId is being assigned a value. Are you actually printing this string to the output and seeing it is an empty string.


                Note, if the entry is cancelled, you cannot call GetAtmStrategyEntryOrderStatus() on the that order any more.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Hi Chelsea,
                  Right, perfect. Thanks again
                  David

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Mindset, 04-21-2026, 06:46 AM
                  0 responses
                  90 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by M4ndoo, 04-20-2026, 05:21 PM
                  0 responses
                  137 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by M4ndoo, 04-19-2026, 05:54 PM
                  0 responses
                  68 views
                  0 likes
                  Last Post M4ndoo
                  by M4ndoo
                   
                  Started by cmoran13, 04-16-2026, 01:02 PM
                  0 responses
                  120 views
                  0 likes
                  Last Post cmoran13  
                  Started by PaulMohn, 04-10-2026, 11:11 AM
                  0 responses
                  72 views
                  0 likes
                  Last Post PaulMohn  
                  Working...
                  X