StepgridHedge trading strategy
This strategy borrows the grid logic from the stepgrid strategy and uses it to trade both the long and short side of a futures market in hedge mode. The strategy uses the same order triggers as stepGrid does on spot, but in quite a different way.
To trade in hedge mode in Gunbot, the two sides act as independent trading pairs like USDT-BTC-LONG and USDT-BTC-SHORT. Both sides can have a position at the same time.
This strategy runs on the long side, meaning that strategy settings and targets only exist on this pair. It trades both longs and shorts using these targets.
Currently supported on Bybit futures, okGunbot & OKX swap markets,
Make sure to enable hedge
/ long/short
mode on the exchange.
For okGunbot and OKX, also make sure to set the account units to contracts in your profile settings on the exchange.
Trading behavior​
The strategy is quite complex, but it can be summarized like this:
Price hits sell step:
- is there a long that can be closed at profit? do that
- else: dca short or skip step
Price hits buy step:
- is there a short that can be closed at profit? do that
- else: dca long or skip step
Grid targets are placed around the last order rate of the newest order of either the long or short side. If a step gets skipped, targets get placed around the skipped rate. Additionally, there are some none configurable methods that prevent dca orders to try to not accumulate too much too fast.
Let's go over a few example trades to explain what happens and how to read the strategy charts:
Short side is in position and price is better than average entry​
The chart of the short pair shows past trades and the average entry price of the current position. In this case, price is profitable and the bot can soon begin closing the short position. There is no ROE target, 'profitable' is meant as just the fact that trading fees are covered.
Long side chart shows the current targets​
The long side chart shows the current targets. In this particular case the long side has a position that is quite far from average entry and is not allowed to further increase the long position size. Because the long side may not DCA at the moment, hitting the next lower target will cause a partial close on the short side.
DCA target exceeded, trailing starts​
Price has now dropped below the DCA target. This triggers an automatic price trailing process. As soon as trailing finishes, the short side is going to take some profits.
Trailing finished​
Trailing is now finished, new targets are placed on the long pair around the rate where trailing finished. Since the expected next order was on the short side, no new orders show on the long side.
Partial short close​
On the short side, a partial close order has appeared. The position size has been reduced by about 30%. There still remains an open short position.
Fast forward a few trades​
Going forward in time a bit, this is how the short side played out. It is still in a short position, has placed several partial close orders and has been adding to the position each time the upper step was hit. By adding to the position even while it is in profit, the strategy can stay active a lot longer during one directional price movement.
The above is just one example, it is not that easy to illustrate this strategy in a way that explains all possible situations. Expect to often see one side profitably trading for some time, while the opposing side will have a position it slowly averages down.
StepGridHedge settings​
Balance settings​
Label | Config Parameter | Default Value | Detailed Description |
---|---|---|---|
Trading limit | TRADING_LIMIT | 20 | The minimum amount you can invest for each order. For Bybit, this represents the notional value, and for OKX / okGunbot, it represents contracts. |
Trading limit short | TRADING_LIMIT_SHORT | 20 | The minimum amount you can invest for each short order. Similar to the trading limit, for Bybit, this represents the notional value, and for OKX / okGunbot, it represents contracts. |
Max buy count | MAX_BUY_COUNT | 75 | This setting limits the maximum position size. When the maximum is reached, the strategy goes into close-only mode. For example, if the maximum is set to 40, your total position size cannot exceed 40 times the amount set as the 'trading limit'. |
Max unhedged | MAX_UNHEDGED | 75 | This setting limits the maximum position size difference from the other side, applying only to orders that add to a position. For instance, if 'max unhedged' is set to 40 and is reached with a long position at 50x the trading limit and short at 10x, the long position cannot grow further until the short position also increases. |
First trades multiplier (long) | FIRST_TRADES_MULTIPLIER | auto | Multiplies the order size for the first few trades on the long side. In 'auto' mode, it automatically generates multiplier values between 1.5 and 5, mostly depending on the imbalance between both sides. If you set a manual value, such as 2, it means that eligible orders will be executed for twice the trading limit. |
First trades threshold (long) | FIRST_TRADES_THRESHOLD | auto | Sets a position size threshold under which the first trades multiplier applies. In 'auto' mode, this usually allows 2 to 3 trades with an increased multiplier before continuing with trades at 1x the trading limit. If manually set to 10, the multiplier applies until the current position reaches 10 times the trading limit. |
First trades multiplier (short) | FIRST_TRADES_MULTIPLIER_SHORT | auto | Similar to the long side setting, this multiplies the order size for the first few trades on the short side. The behavior in 'auto' mode and manual settings is the same as for the long side. |
First trades threshold (short) | FIRST_TRADES_THRESHOLD_SHORT | auto | This setting works similarly to its counterpart for the long side, setting a threshold under which the first trades multiplier applies, with identical behavior in 'auto' mode and when manually set. |
Customize grid​
Label | Config Parameter | Default Value | Detailed Description |
---|---|---|---|
Period | PERIOD | 15 | Sets which candle period is used to calculate auto step size and trailing range. A lower value like 15 increases trading frequency and risk by using shorter duration candles. |
Use trend | USE_TREND | false | This option allows the strategy to choose a trading side based on trend data from multiple timeframe charts, altering the trading limit accordingly. For instance, during a long-only phase, the trading limit for longs might be doubled while short orders can only close positions, and vice versa for a short-only phase. In undecided market conditions, both sides operate with the regular trading limit and can both dca and close positions. |
Trend variant | TREND_VARIANT | 4h | Selects the data source for determining market direction, with options including '4h', '1h_15m', and 'custom'. Each setting affects trading behavior differently, such as modifying trading limits based on perceived market trends. |
Auto step size | AUTO_STEP_SIZE | true | When enabled, the bot automatically determines an appropriate grid step size based on the current volatility of the trading pair. |
Step size | STEP_SIZE | 500 | Sets a fixed grid step size for buy and sell orders when auto step size is not enabled. For example, setting 500 on USDT-BTC configures the bot to trade each time the price moves by 500 USDT. |
Pct step size | PCT_STEP_SIZE | false | Enables the step size to be defined as a percentage rather than a fixed amount, affecting how grid steps are calculated relative to price changes. |
Enforce step size | ENFORCE_STEP | false | Ensures that the defined step size is adhered to strictly. This can be particularly useful for maintaining precise balance management, as it prevents orders from being executed unless they meet or exceed the targeted step improvement. |
Minimum step up pct | MIN_STEP_UP_PCT | 0 | Sets a minimum percentage for step size increases, to override the automatic step size if necessary. For instance, a setting of 1% ensures that the step up will not be less than 1% of the price, unless the auto step size already exceeds this value. |
Minimum step down pct | MIN_STEP_DOWN_PCT | 0 | Similar to the minimum step up percentage, this setting establishes a floor for step size reductions, ensuring that step downs are not less than a set percentage of the price, unless the auto step size is higher. |
Minimum step asymmetric | MIN_STEP_ASYMMETRIC | true | When enabled, this setting applies the minimum step size only in the direction of dollar-cost averaging (DCA) for the currently smaller position. For example, if the short position is smaller than the long, the 'min step up pct' will apply to steps up, but not to steps down. |
Advanced​
Label | Config Parameter | Default Value | Detailed Description |
---|---|---|---|
Stop after close (long) | STOP_AFTER_CLOSE_LONG | false | When enabled, this setting stops all long trading activities once the current long position has been completely closed, preventing any new long positions from being opened until re-enabled. |
Stop after close (short) | STOP_AFTER_CLOSE_SHORT | false | Operates like its counterpart for long positions, stopping all short trading activities once the current short position is fully closed, to prevent opening new short positions until it is re-enabled. |
Buy enabled | BUY_ENABLED | true | This setting allows you to enable or disable the placement of long orders, providing control over whether new long positions can be initiated. |
Sell enabled | SELL_ENABLED | true | Similar to 'Buy enabled', this controls whether you can initiate new short positions by enabling or disabling the placement of short orders. |
Close long enabled | CLOSE_LONG_ENABLED | true | Allows you to enable or disable the ability to partially or fully close long positions, providing flexibility in position management. |
Close short enabled | CLOSE_SHORT_ENABLED | true | Allows you to enable or disable the ability to partially or fully close short positions, similar to the setting for long positions. |
Panic close | PANIC_CLOSE | false | Enables the immediate closure of all open positions at market price, useful in situations where a rapid exit from the market is necessary. |
SMA period | SMAPERIOD | 50 | Defines the number of candles used to calculate support and resistance levels, which are then used to calculate trailing ranges. The default setting of 50 is generally adequate, but can be adjusted based on specific trading needs. |
ATR period | ATR_PERIOD | 50 | Sets the number of candles used to calculate the Average True Range (ATR), which is then used to determine auto step size. The default setting is typically suitable for most situations. |
Buydown exponent | BUYDOWN_EXPONENT | 0.5 | Determines the exponent used in the exponential buydown function, which helps manage the distance between DCA trades and the average entry price. A tool is available for experimenting with different values to find the most suitable setting for your strategy: use this code example to experiment. When in doubt, use default! |
Instant open threshold (long) | INSTANT_OPEN_THRESHOLD_LONG | 99999 | Specifies the minimum size of a long position required to engage 'always in position' trading on the short side. This behavior ensures continuous market engagement by starting to trail for a new position immediately after one is closed. Note: This setting is incompatible with 'enforce step size'. |
Instant open threshold (short) | INSTANT_OPEN_THRESHOLD_SHORT | 99999 | Operates similarly to the long threshold, specifying the minimum size of a short position required for continuous trading on the long side. This facilitates an aggressive trading posture by ensuring immediate market re-engagement after a position closure. Note: Incompatible with 'enforce step size'. |
Static close qty | STATIC_CLOSE_QTY | false | When enabled, every order to close a position uses the same quantity: one times the trading limit. This can simplify the management of closing trades, making them more predictable. |
Static close qty allow loss | STATIC_CLOSE_QTY_LOSS | false | This setting, when enabled and combined with 'static close qty', allows the strategy to place partial close orders at a loss under certain conditions, such as when both trading sides have negative unrealized profits and the cumulative profit history is positive on the side being closed. This can help manage risks and recover from adverse market movements more effectively. |
Other parameters
Besides settings mentioned on this page, no other strategy setting has any effect on stepgridhedge.