Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 mjbatts91, Yesterday, 04:48 PM
    2 responses
    23 views
    0 likes
    Last Post mjbatts91  
    Started by pibrew, Today, 06:10 PM
    1 response
    16 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by actualfacts.2021, 07-25-2021, 03:11 PM
    8 responses
    1,184 views
    0 likes
    Last Post linkcou
    by linkcou
     
    Started by reynoldsn, Today, 07:11 PM
    0 responses
    4 views
    0 likes
    Last Post reynoldsn  
    Started by needsomehelp147, 04-29-2024, 06:43 AM
    2 responses
    20 views
    0 likes
    Last Post needsomehelp147  
    Working...
    X