5/5
## Automating Your GMX Trades: Setting Take Profit and Stop Loss Orders Managing perpetual positions effectively often involves setting predefined exit points to secure profits or limit losses. Constantly monitoring the market to manually close positions at specific price levels can be inefficient and stressful. GMX provides automated Take Profit (TP) and Stop Loss (SL) orders directly within its interface, simplifying position management. This lesson explains what TP/SL orders are, how they function on GMX, and how to set them when opening Long and Short positions. ### Understanding Take Profit (TP) and Stop Loss (SL) These are two fundamental order types used to automate the closing of your trading positions: 1. **Take Profit (TP):** This order automatically closes your position when the market price reaches a predetermined target price that represents a profit. * For **Long positions**, the TP order triggers when the market price *rises* to or goes above your specified TP price. * For **Short positions**, the TP order triggers when the market price *falls* to or goes below your specified TP price. 2. **Stop Loss (SL):** This order automatically closes your position when the market price reaches a predetermined price level that represents an acceptable loss, thereby preventing further potential losses. * For **Long positions**, the SL order triggers when the market price *falls* to or goes below your specified SL price. * For **Short positions**, the SL order triggers when the market price *rises* to or goes above your specified SL price. ### The GMX Mechanism: Three Orders in One When you initiate a position on GMX and simultaneously set TP and SL parameters through the user interface, the platform doesn't just create one order. Instead, it bundles three distinct requests into a single transaction: 1. **Primary Order:** This opens your actual position (e.g., Long ETH or Short ETH). 2. **Conditional Take Profit Order:** This is an order programmed to close your position *only if* the market price reaches your specified Take Profit level. 3. **Conditional Stop Loss Order:** This is an order programmed to close your position *only if* the market price reaches your specified Stop Loss level. Only one of the conditional orders (TP or SL) can ever execute, as they are tied to the primary position. Once either the TP or SL price is hit and the position is closed, the other conditional order becomes irrelevant. ### Auto Cancel: Preventing Orphaned Orders A crucial feature associated with GMX's TP/SL system is "Auto Cancel." Consider what happens if you manually close your position *before* the market price hits either your TP or SL level. Without Auto Cancel, the separate conditional TP and SL orders would remain active on the GMX backend, even though the position they relate to no longer exists. This could lead to confusion or unintended behaviour. The Auto Cancel feature solves this. It ensures that whenever your main position is closed – whether manually by you, automatically via a TP trigger, or automatically via an SL trigger – any associated, outstanding conditional TP or SL orders linked to that position are automatically cancelled by the GMX protocol. * **GMX User Interface (UI):** When setting TP/SL while opening a position via the standard GMX web interface, Auto Cancel is **enabled by default**. You don't need to take any extra steps. * **Direct Smart Contract Interaction:** If you are interacting with GMX programmatically (e.g., building a trading bot directly on the smart contracts), you **must explicitly set** the Auto Cancel parameter to `true` for your TP and SL orders to ensure they are automatically cleaned up when the main position closes. ### Example 1: Setting TP/SL for a Long ETH/USD Position Let's walk through setting up a Long position with TP and SL. * **Scenario:** You want to open a Long position for 0.01 ETH against USD. * **Market Conditions:** Assume the current ETH price is fluctuating around $2050 - $2052. * **Your Goal:** * Take Profit if the ETH price increases to $2100. * Stop Loss if the ETH price decreases to $2000. * **Setting Up the Order (GMX UI):** 1. Select the "Long" tab. 2. Enter the collateral amount (e.g., 0.01 ETH) and choose your desired leverage (e.g., 1x). 3. Locate the "Take Profit / Stop Loss" section. 4. In the "Take Profit" input field, enter the target price: `2100`. The interface will typically show an estimated Profit and Loss (PnL) for this outcome (e.g., +$0.49, +2.37%). 5. In the "Stop Loss" input field, enter the stop price: `2000`. The interface will show the estimated PnL if the stop is hit (e.g., -$0.50, -2.51%). * **Outcome:** When you click the "Long ETH" button and confirm the transaction, GMX will process the request to create the three underlying orders: 1. An order to open your 0.01 ETH Long position at the current market price. 2. A conditional order to close the position if the price reaches or exceeds $2100 (TP). 3. A conditional order to close the position if the price reaches or falls below $2000 (SL). (Auto Cancel will be enabled for the TP and SL orders). ### Example 2: Setting TP/SL for a Short ETH/USD Position Now, let's consider setting up a Short position. Remember, for Shorts, you profit when the price goes down, and you lose when the price goes up. * **Scenario:** You want to open a Short position for ETH against USD (e.g., using 0.009994 ETH collateral). * **Market Conditions:** Assume the current ETH price is around $2049 - $2051. * **Your Goal (Opposite of Long):** * Take Profit if the ETH price *decreases* to $2000. * Stop Loss if the ETH price *increases* to $2100. * **Setting Up the Order (GMX UI):** 1. Select the "Short" tab. 2. Enter the collateral amount and choose leverage. 3. In the "Take Profit / Stop Loss" section: 4. In the "Take Profit" input field, enter the target price: `2000`. The UI will show an estimated PnL (Note: Be mindful that UI PnL estimations might occasionally display unexpected values; always double-check your price targets). 5. In the "Stop Loss" input field, enter the stop price: `2100`. The UI will show the estimated PnL if the stop is hit (e.g., -$2.43, -5.81%). * **Outcome:** Clicking "Short ETH" and confirming the transaction will create: 1. An order to open your Short ETH position. 2. A conditional order to close the position if the price reaches or falls below $2000 (TP). 3. A conditional order to close the position if the price reaches or exceeds $2100 (SL). (Auto Cancel will be enabled for the TP and SL orders). By utilizing the Take Profit and Stop Loss features on GMX, you can implement a more disciplined and automated approach to managing your perpetual swap positions, defining your exit points upfront based on target prices rather than requiring constant manual intervention. Understanding the underlying three-order mechanism and the role of Auto Cancel provides a clearer picture of how GMX executes these automated strategies.
Managing perpetual positions effectively often involves setting predefined exit points to secure profits or limit losses. Constantly monitoring the market to manually close positions at specific price levels can be inefficient and stressful. GMX provides automated Take Profit (TP) and Stop Loss (SL) orders directly within its interface, simplifying position management. This lesson explains what TP/SL orders are, how they function on GMX, and how to set them when opening Long and Short positions.
These are two fundamental order types used to automate the closing of your trading positions:
Take Profit (TP): This order automatically closes your position when the market price reaches a predetermined target price that represents a profit.
For Long positions, the TP order triggers when the market price rises to or goes above your specified TP price.
For Short positions, the TP order triggers when the market price falls to or goes below your specified TP price.
Stop Loss (SL): This order automatically closes your position when the market price reaches a predetermined price level that represents an acceptable loss, thereby preventing further potential losses.
For Long positions, the SL order triggers when the market price falls to or goes below your specified SL price.
For Short positions, the SL order triggers when the market price rises to or goes above your specified SL price.
When you initiate a position on GMX and simultaneously set TP and SL parameters through the user interface, the platform doesn't just create one order. Instead, it bundles three distinct requests into a single transaction:
Primary Order: This opens your actual position (e.g., Long ETH or Short ETH).
Conditional Take Profit Order: This is an order programmed to close your position only if the market price reaches your specified Take Profit level.
Conditional Stop Loss Order: This is an order programmed to close your position only if the market price reaches your specified Stop Loss level.
Only one of the conditional orders (TP or SL) can ever execute, as they are tied to the primary position. Once either the TP or SL price is hit and the position is closed, the other conditional order becomes irrelevant.
A crucial feature associated with GMX's TP/SL system is "Auto Cancel." Consider what happens if you manually close your position before the market price hits either your TP or SL level. Without Auto Cancel, the separate conditional TP and SL orders would remain active on the GMX backend, even though the position they relate to no longer exists. This could lead to confusion or unintended behaviour.
The Auto Cancel feature solves this. It ensures that whenever your main position is closed – whether manually by you, automatically via a TP trigger, or automatically via an SL trigger – any associated, outstanding conditional TP or SL orders linked to that position are automatically cancelled by the GMX protocol.
GMX User Interface (UI): When setting TP/SL while opening a position via the standard GMX web interface, Auto Cancel is enabled by default. You don't need to take any extra steps.
Direct Smart Contract Interaction: If you are interacting with GMX programmatically (e.g., building a trading bot directly on the smart contracts), you must explicitly set the Auto Cancel parameter to true
for your TP and SL orders to ensure they are automatically cleaned up when the main position closes.
Let's walk through setting up a Long position with TP and SL.
Scenario: You want to open a Long position for 0.01 ETH against USD.
Market Conditions: Assume the current ETH price is fluctuating around $2050 - $2052.
Your Goal:
Take Profit if the ETH price increases to $2100.
Stop Loss if the ETH price decreases to $2000.
Setting Up the Order (GMX UI):
Select the "Long" tab.
Enter the collateral amount (e.g., 0.01 ETH) and choose your desired leverage (e.g., 1x).
Locate the "Take Profit / Stop Loss" section.
In the "Take Profit" input field, enter the target price: 2100
. The interface will typically show an estimated Profit and Loss (PnL) for this outcome (e.g., +$0.49, +2.37%).
In the "Stop Loss" input field, enter the stop price: 2000
. The interface will show the estimated PnL if the stop is hit (e.g., -$0.50, -2.51%).
Outcome: When you click the "Long ETH" button and confirm the transaction, GMX will process the request to create the three underlying orders:
An order to open your 0.01 ETH Long position at the current market price.
A conditional order to close the position if the price reaches or exceeds $2100 (TP).
A conditional order to close the position if the price reaches or falls below $2000 (SL).
(Auto Cancel will be enabled for the TP and SL orders).
Now, let's consider setting up a Short position. Remember, for Shorts, you profit when the price goes down, and you lose when the price goes up.
Scenario: You want to open a Short position for ETH against USD (e.g., using 0.009994 ETH collateral).
Market Conditions: Assume the current ETH price is around $2049 - $2051.
Your Goal (Opposite of Long):
Take Profit if the ETH price decreases to $2000.
Stop Loss if the ETH price increases to $2100.
Setting Up the Order (GMX UI):
Select the "Short" tab.
Enter the collateral amount and choose leverage.
In the "Take Profit / Stop Loss" section:
In the "Take Profit" input field, enter the target price: 2000
. The UI will show an estimated PnL (Note: Be mindful that UI PnL estimations might occasionally display unexpected values; always double-check your price targets).
In the "Stop Loss" input field, enter the stop price: 2100
. The UI will show the estimated PnL if the stop is hit (e.g., -$2.43, -5.81%).
Outcome: Clicking "Short ETH" and confirming the transaction will create:
An order to open your Short ETH position.
A conditional order to close the position if the price reaches or falls below $2000 (TP).
A conditional order to close the position if the price reaches or exceeds $2100 (SL).
(Auto Cancel will be enabled for the TP and SL orders).
By utilizing the Take Profit and Stop Loss features on GMX, you can implement a more disciplined and automated approach to managing your perpetual swap positions, defining your exit points upfront based on target prices rather than requiring constant manual intervention. Understanding the underlying three-order mechanism and the role of Auto Cancel provides a clearer picture of how GMX executes these automated strategies.
An essential explanation to Setting Take Profit and Stop Loss Orders on GMX - Master setting automated Take Profit and Stop Loss limits for Long and Short trades on GMX. Grasp the underlying three-order system and the vital Auto Cancel feature for efficient position management.
Previous lesson
Previous
Next lesson
Next
Give us feedback
Cyfrin Updraft has partnered with GMX to provide SSCD+ certifications vouchers to the first 25 students who demonstrate the completion of this course and are building on top of GMX. Join the GMX Discord server to redeem your coupon, or navigate to the docs to learn more!
Course Overview
About the course
Mechanics and contract architecture of the GMX protocol
Token pricing and fees
Liquidity: GM pools and GLV vaults
Math, funding rates, liquidation pricing, P&L calculations
Limit orders, take profit orders, stop loss, and stop market orders
Auto-cancel and auto-deleveraging
GLP, esGMX, GMX staking and delegation
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Last updated on June 26, 2025
Duration: 8min
Duration: 1h 19min
Duration: 1h 24min
Duration: 16min
Duration: 11min
Duration: 11min
Duration: 6min
Course Overview
About the course
Mechanics and contract architecture of the GMX protocol
Token pricing and fees
Liquidity: GM pools and GLV vaults
Math, funding rates, liquidation pricing, P&L calculations
Limit orders, take profit orders, stop loss, and stop market orders
Auto-cancel and auto-deleveraging
GLP, esGMX, GMX staking and delegation
DeFi Developer
$75,000 - $200,000 (avg. salary)
Smart Contract Engineer
$100,000 - $150,000 (avg. salary)
Web3 developer
$60,000 - $150,000 (avg. salary)
Web3 Developer Relations
$85,000 - $125,000 (avg. salary)
Smart Contract Auditor
$100,000 - $200,000 (avg. salary)
Security researcher
$49,999 - $120,000 (avg. salary)
Last updated on June 26, 2025