Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

GetAtmStrategyStopTargetOrderStatus Order Name Invalid

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

    GetAtmStrategyStopTargetOrderStatus Order Name Invalid

    I have the following code that is part of a one click order entry script that worked fine while testing using the Playback account, but is triggering as error message when using Live.

    The error message is "GetAtmStrategyStopTargetOrderStatus method error Order name Stop1 is invalid"

    The script submits an ATM Strategy

    This is the code. . .


    string[] entryOrder = GetAtmStrategyEntryOrderStatus(atmStrategyId);

    if (entryOrder[2].ToString() == "PartFilled" || entryOrder[2].ToString() == "Filled")
    {
    for (int i = 1; i <= noOfATMStops; i++)
    {
    if (al.Count != i)
    {
    string[,] orders = GetAtmStrategyStopTargetOrderStatus("Stop"+i, atmStrategyId);
    if (orders.Length > 0)
    {
    al.Add(i);
    for (int j = 0; j < orders.GetLength(0); j++)
    {
    AtmStrategyChangeStopTarget(0, stopPrice, "Stop"+i, atmStrategyId);
    }
    }
    }
    }

    Looking around at other posts they seem to suggest that the error occurs if you use GetAtmStrategyStopTargetOrderStatus before the order is in the right state, but you can see above I check to make sure the order is "Filled", so just seeing if anyone has come across this or can see a problem with what I have done.

    #2
    Hello |Scrumbeans,

    The error typically means the stop has not been created (or submitted) yet.

    Adding the condition the position is taken before calling the method can ensure the stop and target have been created.

    Code:
    if (atmStrategyId.Length > 0){
    // You can change the stop price
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat)
    GetAtmStrategyStopTargetOrderStatus("Stop1", atmStrategyId);
    }
    The SampleAtmStrategy included with NinjaTrader has sample code on line 99.

    It would also be possible to wait until the next update of OnBarUpdate().
    For example you could check that a bool is true before checking the stop status, and below this set the bool to true only after the position is taken.

    Code:
    // this would be declared within the scope of the class
    private bool positionActive;
    
    // within OnBarUpdate check if the positionActive bool has been set to true first
    if (positionActive)
    GetAtmStrategyStopTargetOrderStatus("STOP1", atmStrategyId);
    
    // by setting the bool to true below where it is checked above, the set value will not be evaluated until the next update of OnBarUpdate()
    if (GetAtmStrategyMarketPosition(atmStrategyId) != MarketPosition.Flat))
    positionActive = true;
    else
    positionActive = false;
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    65 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    139 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