Advanced Stop Losses using Stop-Limit Orders in TradingView Webhooks
Advanced stop-loss techniques, including the new stop-loss limit feature, provides greater control over your trades by reducing slippage and enhancing precision in NinjaTrader 8's TP/SL + OCO bracket orders.
This week we've added a new advanced option to how stop losses work in TP/SL + OCO bracket orders. Typically, in our alert messages we can set a take_profit
level and a stop_loss
level that translates into a limit order and stop market orders in NinjaTrader 8.
We just added the ability to set stop_loss_limit
, which can be used in place of a stop_loss
. The main difference is stop_loss_limit
will create a limit order for the stop instead of a market order.
For those unfamiliar, a stop-limit order requires a stop trigger price and a limit order price. The stop trigger is the level beyond which the limit order gets placed.
If you're new to CrossTrade, dive right in and learn how to send orders from TradingView to NinjaTrader.
What is a Limit Order?
A limit order is an instruction to buy or sell a security at a specific price or better. Essentially, you define the maximum price you are willing to pay (in the case of buying) or the minimum price you are willing to accept (in the case of selling).
If you submit a limit order, it will either be filled immediately at the specified price or better if the market is already trading at that level, or it will sit in the market until those conditions are met.
For example, if you have a buy limit order at 7000, it will only execute if the market price reaches 7000 or below. If the current market price is 7020, the order will remain pending until the market falls to 7000 or better.
What is a Stop-Limit Order?
A stop-limit order adds a layer of conditionality to a limit order. It consists of two components:
- Stop Price: This is the price at which the order is triggered and effectively converted into a limit order.
- Limit Price: Once the stop price is reached, the order turns into a limit order with a specified limit price that defines the worst acceptable fill price.
The stop price essentially serves as a trigger, and the limit price ensures that once the trigger is activated, the order will only execute under acceptable conditions. This combination provides a useful way to ensure that you enter or exit positions at specific price levels, but only after a trigger condition is met.
How Does a Stop-Limit Order Work?
Consider that you are trading a contract and want to enter the market only if the price starts to move in a certain direction. You set a stop-limit order with a stop price of 7000 and a limit price also of 7000. This means that when the price reaches 7000, your order is activated as a limit order to buy or sell at 7000 or better.
Why Use a Stop Trigger Instead of an Immediate Limit Order?
Conditional Activation
A stop-limit order is useful when you want to wait until a certain price level is reached before executing an order. If you place a simple limit order immediately, it will be active in the market regardless of the current price, which might not be desirable if you want more control over your entry or exit.
For example, if you are short on a futures contract like the ES (E-mini S&P 500), you might want to protect your position by covering it only if the market starts to move against you and hits 7000. If the market is still at 6950, placing a limit order at 7000 without any stop condition could result in premature execution—there's no immediate need to exit since your target price hasn’t been triggered yet.
Price Protection for Loss or Breakout
Stop-limit orders are often employed in either stop-loss or breakout strategies.
- Stop-Loss: For a stop-loss scenario, the goal is to trigger the order once the price moves against your position to a certain level, limiting your losses.
- Breakout Entry: In a breakout scenario, you only want to enter the market if the price moves beyond a certain point, signaling momentum in that direction. The stop ensures you are entering at a point that fits your strategy and logic.
Avoiding Premature Execution
Without the stop condition, placing a limit order at or near the current market price might result in an immediate fill if the conditions are met. This can be problematic when you intend to wait for specific market behavior—such as a confirmation of momentum in one direction—before executing your trade.
The stop price acts as a specific trigger point, ensuring that your order is only activated when predefined conditions are satisfied, helping you stick to your trade logic rather than executing too soon.
Stop Loss Limit Orders in CrossTrade
As I mentioned earlier, we can set a stop_loss
at a price level in a CrossTrade webhook, which translates into a stop market order.
By using stop_loss_limit
, we create a stop-limit order instead. Recall that a stop-limit requires both a stop price trigger and a limit order price.
The key reason the limit order can't just be submitted immediately, instead of waiting for the stop trigger, lies in the fundamental difference in the behavior and intention of a stop-limit order versus a regular limit order.
Using stop_loss_limit
on its own, the stop trigger and limit price will be at the same level. But in fast moving markets, it's possible the underlying price will quickly move past your limit price without triggering, exposing you to risk of unclosed positions.
To combat this, you can optionally include a stop_loss_stop
value in addition to stop_loss_limit
to tell the stop-limit order where to set the stop trigger. For example, all of the following are valid:
Example 1:
stop_loss=1000;
Example 2:
stop_loss_limit=1000;
Example 3:
stop_loss_stop=1005;
stop_loss_limit=1000;
In Example 3, assume our position is short and we want our stop loss to hit at at a price level of 1000, but trigger that order when the price drops below 1005.
In Example 2, the stop_loss_stop
price, though not explicitly provided, is set at 1000 to match the limit price.
Example 1 is a typical stop market order that triggers at level 1000.
For more information: https://docs.crosstrade.io/webhooks/advanced-options/bracket-orders
Example Trading Scenario
- You're going short 2 ES contracts and want to place a stop-limit order to protect yourself in case the market moves against you.
- Suppose the current price is
6950
, but you’re willing to exit your position only if the market reaches or exceeds7000
. Setting:- Stop Price =
7000
- Limit Price =
7000
(or slightly higher, e.g.,7005
)
- Stop Price =
- The stop-limit order is effectively inactive until the price reaches
7000
. Only when this trigger condition is met, the limit order becomes active, at which point it attempts to execute at7000
(or up to the limit price).
If you instead submitted a limit order immediately at 7000
:
- That order would sit on the book and potentially execute well before the market hits your stop level (if the market oscillates up to that point), which contradicts the protective intent of a stop-loss strategy.
Full Webhook Message Payload
Following the example above, if you wanted to craft the full payload inside of the webhook message (e.g., in TradingView), it would look like this:
key=your-secret-key;
command=PLACE;
account=sim101;
instrument=ES 12-24;
action=SELL;
qty=2;
order_type=MARKET;
TIF=DAY;
stop_loss_stop=7000;
stop_loss_limit=7005;
In this example, we trigger the limit order in NinjaTrader 8 to set if and only if the underlying price crosses above the stop price, 7000.
Summary
The stop component of a stop-limit order ensures that the order is only triggered when a specific price threshold is reached. This makes it suitable for stop-loss strategies or conditional entry points that depend on the market's behavior.
In contrast, a limit order placed immediately would be continuously active, subject to filling based on market price movements, without any conditional activation criteria. This defeats the purpose of waiting until a certain price is reached before acting.
This functionality is intended for advanced traders who want precise control over their stop loss strategy.