=== POSITION OPENED - Starting tick monitoring (Long) at 12/8/2025 5:00:08 AM ===
[DEBUG] Account ‘Playback101’ has 1 total positions
[POSITION FOUND] LONG 2 contracts on MNQ 12-25
Yellow bar started - Tick #1 at 12/8/2025 6:02:39 AM (Threshold: 1)
[DEBUG] Account ‘Playback101’ has 1 total positions
[POSITION FOUND] LONG 2 contracts on MNQ 12-25
*** YELLOW BAR DETECTED (1 ticks) - Exiting LONG position at 12/8/2025 6:02:39 AM ***
Submitted SELL MARKET order: 2 contracts
[DEBUG] Account ‘Playback101’ has 1 total positions
[POSITION FOUND] LONG 2 contracts on MNQ 12-25
BUT, the position was not EXITED on the chart. Could this be because:
ATM Strategy Conflict Issue: I already have a Stop Loss and Target Set
When you manually enter a trade via Chart Trader with an ATM Strategy (containing Stop Loss and Profit Target), the ATM creates protective orders that “manage” your position.
What happens when an indicator tries to exit an ATM-managed position using CreateOrder(): ???
Maybe The Code Execution Setting: Somehow? Any ideas will be much appreciated.
I can implement an Exit Only Strategy as follows though I prefer to have the indicator only using the exit strategy:
public class IntellusMomentumStrategy : Strategy
{
private IntellusMomentumDM intellusMomentum;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Calculate = Calculate.OnEachTick; // KEY: Tick-level processing
}
else if (State == State.DataLoaded)
{
intellusMomentum = IntellusMomentumDM();
}
}
protected override void OnBarUpdate()
{
// === ENTRY LOGIC (On Bar Close) ===
if (IsFirstTickOfBar)
{
if (Position.MarketPosition == MarketPosition.Flat)
{
// Check for green bar entry signal
if (intellusMomentum.YellowBar[1] == 0 && /* other conditions */)
{
EnterLong();
}
}
}
// === EXIT LOGIC (Intraday Ticks) ===
if (Position.MarketPosition == MarketPosition.Long && !IsFirstTickOfBar)
{
// Exit on FIRST TICK of yellow bar
if (intellusMomentum.YellowBar[0] == 1)
{
ExitLong(); // INSTANT execution!
}
}
}
Your logic seems fine to me. The only thing I can think of is: are you submitting the order after your CreateOrder() call? Create only constructs the order object it doesn’t submit it to be filled. You need to call tradingAccount.Submit() with your new order for it to get into the market.
// METHOD 1: Close ATM Strategy (if position was entered with ATM)
bool atmClosed = false;
foreach (StrategyBase strategy in tradingAccount.Strategies.ToList())
{
if (strategy.Instrument == Instrument)
{
strategy.CloseStrategy("Yellow Bar Exit");
Print("*** Closed ATM Strategy on yellow bar ***");
atmClosed = true;
}
}
// METHOD 2: If no ATM (manual entry without ATM), use CreateOrder
if (!atmClosed)
{
// Original CreateOrder logic as fallback
// ...
}
Ok, I have created an Indicator and now I want to: include in the indicator a function to exit a position using intraday tick data before bar close. I am averaging when price goes above or below a percentage of a single bar when in a trade using momentum levels. A line crossing almost through a certain known CCI level for exiting a position though I also need to close the position before line crosses all the way through on bar close.
[size=18pt]Guide: How to use CreateOrder() with ATM Strategies[/size]
Integrating CreateOrder() with an Advanced Trade Management (ATM) strategy is essential for developers who need to launch orders from indicators or add-ons while still utilizing NinjaTrader’s built-in exit management (Stop Losses and Profit Targets).
Step-by-Step Implementation:
1. Set the Magic String:
The most critical part of this process is the “name” parameter. For StartAtmStrategy() to identify and bind to your entry, the name MUST be [color=#FF0000]“Entry”[/color] [(Source)].
2. Example Code Snippet:
// Ensure you have a valid reference to your Account object
Account myAccount = ...;
// Create the Order object first
Order entryOrder = myAccount.CreateOrder(
Instrument,
OrderAction.Buy,
OrderType.Market,
OrderEntry.Automated,
TimeInForce.Day,
1, // Quantity
0, // Limit Price
0, // Stop Price
string.Empty,
"Entry", // CRITICAL: This exact string is required for ATM
Core.Globals.MaxDate,
null
);
// Bind the saved ATM template to this specific order
// Replace "MyAtmTemplate" with your exact saved template name
NinjaTrader.NinjaScript.AtmStrategy.StartAtmStrategy("MyAtmTemplate", entryOrder);
// Submit the finalized order to the exchange
myAccount.Submit(new[] { entryOrder });
Why use this over managed orders?
[list]
[*] Indicator Trading: Allows indicators to execute trades (managed orders are Strategy-only).
[*] Custom UI: Perfect for creating custom buttons or “Buy/Sell” interfaces in Add-ons.
[*] Multi-Account: Easily loop through different Account objects to place the same ATM order across multiple accounts.
[/list]
Technical Limitations in 2025:
[list]
[*] No Backtesting: ATM strategies are processed in the NinjaTrader UI layer and will not execute on historical data [(Ref)].
[*] Position Isolation: Positions managed by an ATM strategy are not automatically tracked by a hosting NinjaScript strategy’s Position property.
[*] Execution Handling: Since this is an unmanaged approach, always use the OnOrderUpdate event to monitor if your “Entry” order was rejected or cancelled.
[/list]
[size=18pt]Exiting ATM-Managed Positions via CreateOrder() (Unmanaged Approach)[/size]
What happens when an indicator attempts to exit an ATM-managed position using CreateOrder()?
The short answer is that the order will be submitted, but the process will be inefficient and prone to errors because the indicator’s order is independent of the ATM’s management system.
Key Outcomes of Using CreateOrder() for ATM Exits
[list]
[*] Independent Order Submission: The CreateOrder() method sends a new, separate exit order to the exchange via the Account object.
[*] No Automatic OCO Cancellation: The new exit order will not automatically cancel the existing ATM-managed Stop Loss (SL) and Profit Target (PT) orders. The ATM management system operates independently.
[*] Position Mismatch: The position tracking within the indicator (Position property) will likely not match the actual position on the account, as ATM positions are considered “unmanaged” by the indicator’s context.
[*] Risk of Over-Trading: If your new exit order fills, the original ATM orders remain active. This leaves open the possibility of those original orders filling later and inadvertently creating a new, unwanted position or reversal.
[/list]
The Recommended Approach
To correctly manage an exit from an indicator for an ATM-managed position, you should not use a simple CreateOrder(). You need a coordinated approach:
Cancel Existing Orders: First, cancel all existing working orders (the SL and PT orders) associated with that position.
Flatten the Position: Only after confirmed cancellation should you submit a market order to close the position entirely.
A cleaner way to achieve this is to iterate through the account’s active strategies collection and call the built-in CloseStrategy() method provided by NinjaTrader.
// Example of accessing the ATM strategy instance to close it cleanly
foreach (var atmStrategy in NinjaTrader.NinjaScript.AtmStrategy.Strategies)
{
// Find the specific strategy instance related to your entry order's ticket
if (atmStrategy.EntryOrder.Instrument.FullName == Instrument.FullName && atmStrategy.Name == "MyTemplateName")
{
// This method cancels existing exits and flattens the position safely
atmStrategy.CloseStrategy();
break;
}
}
For reliable results, always use the intended API calls for closing positions rather than submitting conflicting, independent orders.
[b]Robust Strategy: Closing Manual ATM Trades via Custom Logic[/size][/b]
If you need a NinjaScript strategy to monitor and close a trade that you [b]manually[/b] entered via Chart Trader (using an ATM), you cannot rely on standard [i]Position.MarketPosition[/i] or [i]ExitLong()[/i]. Instead, you must monitor the account's live position and use the [i]CloseStrategy()[/i] method.
[b]Key Advantages of this Approach:[/b]
[list]
[*] [b]Direct Account Monitoring:[/b] Uses [i]Account.MarketPosition[/i] to "see" trades not placed by the strategy.
[*] [b]Safe ATM Teardown:[/b] [i]CloseStrategy()[/i] automatically cancels your working Stop Loss/Profit Targets before flattening.
[*] [b]Indicator Integration:[/b] Seamlessly links custom indicator signals (e.g., [i]intellusMomentum[/i]) to manual trade exits.
[/list]
[b]Implementation Code Snippet:[/b]
[code]
protected override void OnBarUpdate()
{
// 1. Robust check: Look at the actual ACCOUNT status, not the strategy's internal position
// This allows the strategy to monitor manual trades entered via Chart Trader
if (Account.MarketPosition[Instrument].Quantity > 0 && !IsFirstTickOfBar)
{
// 2. Your custom indicator exit condition
// Example: Exiting on the first tick of a "Yellow Bar" signal
if (intellusMomentum.YellowBar[0] == 1)
{
CloseActiveAtmStrategy();
}
}
}
private void CloseActiveAtmStrategy()
{
// 3. Iterate through all active ATM strategies on the current account
foreach (NinjaTrader.NinjaScript.AtmStrategy.AtmStrategy atm in Account.Strategies)
{
// Ensure the ATM belongs to this instrument and is currently managing a position
if (atm.EntryOrder.Instrument.FullName == Instrument.FullName && atm.IsActive)
{
// 4. THE KEY METHOD: Safely cancels exits and flattens the position
// This is the gold standard for robust exits in 2025
atm.CloseStrategy();
Print("Exit Triggered: Manual ATM closed by IntellusMomentum signal.");
break;
}
}
}
[/code]
[b]Why this is essential for 2025:[/b]
In NinjaTrader 8, a Strategy's internal [i]Position[/i] property only tracks trades executed by that specific script. By using [i]Account.MarketPosition[/i], you create a "Supervisor" script that can manage any position on the account, regardless of how it was opened. Using [i]atm.CloseStrategy()[/i] ensures that your protective brackets are not left "orphaned" at the exchange after the position is closed.
For further documentation, see: [url=ninjatrader.com]NinjaScript Help Guide: CloseStrategy[/url].
I am using CreateOrder() call AND Account.Submit() built into the indicator though I was thinking about using the Strategy route for the exits. It is functioning properly now though before I only used CreateOrder() and did not add Account.Submit() so in the logs it showed Exit Order was submitted as the order was created though it did not actually submit.