Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Getting error when calling GetAtmStrategyStopTargetOrderStatus

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

    Getting error when calling GetAtmStrategyStopTargetOrderStatus

    Hi,

    When I call GetAtmStrategyStopTargetOrderStatus, I get the following error.
    'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid
    GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Stop1' is invalid



    protected override void OnBarUpdate()
    {
    if(!PerformTakePosition())
    {
    if (!isAtmStrategyCreated)
    return;


    if (orderId.Length > 0)
    {
    string[] status = GetAtmStrategyEntryOrderStatus(orderId);

    if (status.GetLength(0) > 0)
    {

    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    {
    orderId = string.Empty;
    }

    PrintTargetOrderStatus();
    PrintStopOrderStatus();



    }
    }
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;
    }

    }

    void PrintTargetOrderStatus()
    {

    if (string.IsNullOrEmpty(atmStrategyId) || string.IsNullOrEmpty(orderId))
    return;

    Print("-----------Target status------------");

    string[,] orders = GetAtmStrategyStopTargetOrderStatus("Target1", atmStrategyId);

    for (int i = 0; i < orders.GetLength(0); i++)
    {
    Print("Average fill price is " + orders[i, 0].ToString());
    Print("Filled amount is " + orders[i, 1].ToString());
    Print("Current state is " + orders[i, 2].ToString());
    }
    }

    void PrintStopOrderStatus()
    {
    if (string.IsNullOrEmpty(atmStrategyId) || string.IsNullOrEmpty(orderId))
    return;

    Print("-----------Stop status------------");

    string[,] orders = GetAtmStrategyStopTargetOrderStatus("Stop1", atmStrategyId);

    if (orders.Length > 0)
    {

    for (int i = 0; i < orders.GetLength(0); i++)
    {
    Print("Average fill price is " + orders[i, 0].ToString());
    Print("Filled amount is " + orders[i, 1].ToString());
    Print("Current state is " + orders[i, 2].ToString());
    }
    }
    }

    #2
    Hello bosajin, thanks for your question.

    This error can come up if the stop or target have not been submitted at the time you call this method. Can you confirm the entry order status before calling this to see if the problem will be resolved:


    I look forward to hearing from you.

    Comment


      #3
      Hi ChrisL,

      this is output of my log.
      status of entry order is Working.


      -----------Order Status------------
      The entry order average fill price is: 0
      The entry order filled amount is: 0
      The entry order order state is: Working
      -----------Target status------------
      'GetAtmStrategyStopTargetOrderStatus' method error: Order name 'Target1' is invalid





      Comment


        #4
        Hello bosajin, thanks for your reply.

        If the order is Working then it has not filled yet. If you call the StopTargetOrder status after the entry order is filled then they should work.

        Kind regards.

        Comment


          #5
          Originally posted by NinjaTrader_ChrisL View Post
          Hello bosajin, thanks for your reply.

          If the order is Working then it has not filled yet. If you call the StopTargetOrder status after the entry order is filled then they should work.

          Kind regards.
          NinjaTrader_ChrisL, reopening a follow-up question on this error being thrown.

          I had coded the following assuming it would account for the status of the entryOrder:

          Code:
          if (GetAtmStrategyMarketPosition(atmStrategyId) != Cbi.MarketPosition.Flat)
          {string[,] targetOrderStatus = GetAtmStrategyStopTargetOrderStatus("Target1", atmStrategyId);}
          However, the error is still thrown. That would mean then that there is enough processing latency between the update to MarketPosition and the subsequent initialization/submission of the Target/Stop bracket such that the evaluation of the MarketPosition alone as a proxy for the creation of the Target/Stop order objects is insufficient... is that a fair assessment?

          UPDATE
          Confirming this is in fact the case. Neither the working status of the entryOrder nor the MarketPosition can adequately address the serial latency between those update events and the actual placement of the Target/Stop orders...

          The error is non-fatal, but clogs up the Log/Output window.
          Last edited by TheFil; 04-27-2022, 08:52 AM.

          Comment


            #6
            HI TheFil, thanks for posting. I will need to test the ATM strategy function GetAtmStrategyStopTargetOrderStatus for myself. I will follow up with more information tomorrow.

            Kind regards,
            -ChrisL

            Comment


              #7
              Hi TheFil, thanks for your patience on this topic. I tested the ATM strategy script that comes with the platform with some modifications and get order status from the method "GetAtmStrategyStopTargetOrderStatus" The example first checks that the ATM is created before calling these methods with:

              if (!isAtmStrategyCreated)
              return;

              The stop and target status shows up as working once the ATM is submitted and the position is open. Here is the full test code:

              Code:
              if (atmStrategyId.Length > 0)
              {
              // You can change the stop price
              if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
              AtmStrategyChangeStopTarget(0, Low[0] - 3 * TickSize, "Stop1", atmStrategyId);
              
              string[,] orders = GetAtmStrategyStopTargetOrderStatus("Target1", atmStrategyId);
              
              if (orders.Length > 0)
              {
               for (int i = 0; i < orders.GetLength(0); i++)
               {
                Print("Average fill price is " + orders[i, 0].ToString());
                Print("Filled amount is " + orders[i, 1].ToString());
                Print("Current state is " + orders[i, 2].ToString());
               }
              }

              Comment


                #8
                Thanks NinjaTrader_ChrisL

                I wrote my script based on that same sample ATM script, actually. So I have the isAtmStrategyCreated check in there.

                This issue occurs in very fast moving markets and is non-fatal so on subsequent iterations of OnBarUpdate(), eventually the order "Target1" is instantiated. Short of making the base "faster" I don't know how else this would be handled.

                Comment


                  #9
                  NinjaTrader_ChrisL

                  Follow up to this...

                  Would calling OnOrderUpdate() and specifying the order name, 'Target1'/'Stop1' be a "safer" way to handle this? I understand that GetAtmStrategyStopTargetOrderStatus() is intended to facilitate this and that generally speaking the ATM specific methods should be utilized, but is there any reason this wouldn't work?

                  Thanks in advance.

                  Comment


                    #10
                    Hi, thanks for the reply. OnOrderUpdate is an event method that gets called by the system to notify the script of an order update. GetAtmStrategyStopTargetOrderStatus must be called by the script so they are different things. As long as the ATM ID is still active this order will work.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by NullPointStrategies, Yesterday, 05:17 AM
                    0 responses
                    72 views
                    0 likes
                    Last Post NullPointStrategies  
                    Started by argusthome, 03-08-2026, 10:06 AM
                    0 responses
                    143 views
                    0 likes
                    Last Post argusthome  
                    Started by NabilKhattabi, 03-06-2026, 11:18 AM
                    0 responses
                    76 views
                    0 likes
                    Last Post NabilKhattabi  
                    Started by Deep42, 03-06-2026, 12:28 AM
                    0 responses
                    47 views
                    0 likes
                    Last Post Deep42
                    by Deep42
                     
                    Started by TheRealMorford, 03-05-2026, 06:15 PM
                    0 responses
                    51 views
                    0 likes
                    Last Post TheRealMorford  
                    Working...
                    X