The mechanism for placing and adjusting stop-loss orders to limit losses. Stop-loss logic can be static (set once at entry) or dynamic (e.g. trailing stops, breakeven stops). In code, a stop loss is usually attached when placing an order or modified during the trade. Many platforms provide built-in methods: for instance, NinjaTrader’s SetStopLoss()
call automatically submits a protective stop when the position opens.
-
Definition: Rules for where to set the stop-loss price. Examples: a fixed 50-pip stop, ATR-based stop, or moving the stop to break-even after X profit.
-
Context: In MQL, the stop-loss price is passed to
OrderSend()
(or modified withOrderModify()
). In cTrader, it’s a parameter toExecuteMarketOrder()
. In NinjaScript, callingSetStopLoss()
inInitialize()
ensures the platform places the stop. The NinjaTrader guide explains thatSetStopLoss()
will “submit a stop … with a price calculated… offset from the position’s average entry price”. -
Example (MQL4):
-
Example (cAlgo):
-
Example (NinjaScript):