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 NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  62 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  134 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  75 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X