Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ATM Strategy: Cancel StopMarket order after 1 Bar

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

    ATM Strategy: Cancel StopMarket order after 1 Bar

    I have an atm strategy set to calculate on bar close running on a 15 minute chart that I wish to have the order closed automatically if it's not filled within one bar. The order type is StopMarket and when the order is executed the Ninjascript Output says the order state is "accepted" instead of "working" so Ninjatrader doesn't automatically close it out after one bar.

    Is there any line of code that would resolve this issue? Needless to say I am less than a novice when it comes to code and the only examples I've found only work if the order state is "working" not "accepted."

    // Print out some information about the order to the output window
    Print("The entry order average fill price is: " + status[0]);
    Print("The entry order filled amount is: " + status[1]);
    Print("The entry order order state is: " + status[2]);

    if (status[2] == "Working" && (BarsSinceEntryExecution() >= 1 || BarsSinceEntryExecution() == -1))
    AtmStrategyCancelEntryOrder(orderId.ToString());

    // If the order state is terminal, reset the order id value
    if (status[2] == "Filled" || status[2] == "Cancelled" || status[2] == "Rejected")
    orderId = string.Empty;
    }
    } // If the strategy has terminated reset the strategy id
    else if (atmStrategyId.Length > 0 && GetAtmStrategyMarketPosition(atmStrategyId) == Cbi.MarketPosition.Flat)
    atmStrategyId = string.Empty;​


    Thank you in advance.

    #2
    Hello ZEROSYSTEM,

    Stop market orders by default go into the accepted status instead of working like limit type orders so that is normal. To find that order you should be able to check for the Accepted status instead of Working in the condition you made.

    if(status[2] == "Accepted"

    Another item here is that BarsSinceEntryExecution is for strategy based orders and not ATM's, you would have to use your own variable to know how many bars it has been since the entry condition became true. You can use an int variable and set it to CurrentBar, then in your condition check if the value of CurrentBar minus your variable is equal or greater to 1. In the section of code where you reset the atm id strings you would need to reset that variable back to 0 before the next entry.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    110 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    59 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    37 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    41 views
    0 likes
    Last Post TheRealMorford  
    Started by Mindset, 02-28-2026, 06:16 AM
    0 responses
    78 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Working...
    X