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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    88 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    134 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
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X