Ocean Theory Grid Trading Strategy
Overview
This strategy utilizes the grid trading method in ocean theory to place buy and sell orders within a preset price range. The strategy features automatic calculation of grid price range and uniform distribution of grid lines, which helps effectively manage risks.
Strategy Logic
The strategy first calculates the upper and lower bounds of the price grid based on user's choice or default settings. There are two ways of calculation: getting the highest and lowest prices in the backtesting period, or computing moving averages over a timeframe. Then grid lines are uniformly distributed according to the number of grids set by user.
The trading signals are generated based on the relationship between price and grid lines. When the price is below a grid line, a long position is opened at the grid line price with fixed quantity; when the price goes above a grid line, the position is closed at the grid line below. As price fluctuates within the grid, the positions change accordingly to gain profit.
Specifically, the strategy maintains a grid line price array and a bool array indicating whether orders are placed at each line. When price is below a line with no orders, long position is opened at the line; when price is above a line while orders exist at the line below, positions are closed at the lower line. Grid trading is implemented this way.
Advantages
-
Grid range is calculated automatically, avoiding manual setting difficulty. Different calculation options are available.
-
Grid lines are distributed evenly to avoid overtrading due to dense grids. Number of grids can be adjusted.
-
Grid trading method effectively controls risks. Profit can be gained as long as price fluctuates within the grid.
-
No price direction assumption, suitable for range-bound market.
-
Customizable commission and position size settings for different trading instruments.
-
Visualization of grid lines helps understand trading situation.
Risks
-
Price breakout risks. Breaking the upper or lower grid limits can lead to greater losses.
-
Excessive grid space risks. Grids too loose cannot profit easily while too narrow increases costs. Balance is needed.
-
Prolonged holding risks. Long holding makes profit difficult yet increases costs.
-
Improper parameter setting risks. Backtesting period or moving average period can affect grid range calculation if set inappropriately.
-
Systemic market risks. More suitable for range-bound instead of long-term trended markets.
Enhancement
-
Optimize grid parameters. Comprehensively consider market conditions, costs etc. to optimize number of grids, lookback period etc.
-
Introduce dynamic grid range adjustment. Adapt grid ranges when significant market change occurs.
-
Incorporate stop loss mechanisms. Set proper stop loss lines to limit losses. Can be adjusted dynamically.
-
Add filters using other indicators. Such as Bollinger Bands, trend indicators etc. to avoid improper trading.
-
Improve capital usage efficiency. Introduce volatility analysis to reduce trading during steady periods.
Conclusion
The strategy realizes risk-controllable range trading by leveraging grid trading principles. The automatic grid calculation and uniform distribution offer advantages that suit various markets through parameter tuning. Risks are limited and easy to operate. However, limitations exist and continuous improvements are needed to adapt to evolving markets. Overall, the strategy provides a standardized and parametric approach to implementing grid trading.
/*backtest
start: 2023-09-12 00:00:00
end: 2023-10-12 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("(IK) Grid Script", overlay=true, pyramiding=14, close_entries_rule="ANY", default_qty_type=strategy.cash, initial_capital=100.0, currency="USD", commission_type=strategy.commission.percent, commission_value=0.1)
i_autoBounds = input(group="Grid Bounds", title="Use Auto Bounds?", defval=true, type=input.bool) // calculate upper and lower bound of the grid automatically? This will theorhetically be less profitable, but will certainly require less attention
i_boundSrc = input(group="Grid Bounds", title="(Auto) Bound Source", defval="Hi & Low", options=["Hi & Low", "Average"]) // should bounds of the auto grid be calculated from recent High & Low, or from a Simple Moving Average- 1
