Adaptive Intelligent Grid Trading Strategy
Overview
This strategy is an adaptive intelligent grid trading strategy based on the TradingView platform, written in Pine Script v4. It overlays on the price chart and creates a grid within specified bounds to generate buy and sell signals.
Strategy Logic
Key Features
-
Pyramiding and Money Management:
- Allows up to 14 additions in the same direction (pyramiding),
- Uses a cash-based strategy to manage position sizes,
- Initial capital is set at 100 USD for simulation purposes,
- A small commission of 0.1% is charged for each trade.
-
Grid Bounds:
- Users can opt to use auto-calculated bounds or manually set the upper and lower boundaries of the grid,
- Auto bounds can be derived from either the recent High & Low of the price or from a Simple Moving Average (SMA),
- Users can define the lookback period for the bounds calculation and adjust the deviation to widen or narrow the bounds.
-
Grid Lines:
- The strategy allows for a customizable number of grid lines within the bounds, with a recommended range between 3 and 15,
- The grid lines are evenly spaced between the upper and lower bounds.
Strategy Logic
-
Entry:
- The script places buy orders when the price falls below a grid line and no existing order is associated with that grid line.
- Each buy order quantity is calculated based on the initial capital divided by the number of grid lines, adjusted for the current price.
-
Exit:
- Sell orders are triggered when the price rises above a grid line, provided there is an open order corresponding to the next lower grid line.
-
Adaptive Grid:
- If set to auto bounds, the grid adapts to changing market conditions by recalculating the upper and lower bounds and adjusting the grid accordingly.
Advantage Analysis
The strategy integrates the systematic nature and efficient execution of grid trading. Allowing pyramiding and using money management can effectively control risks. The auto-adapting grid fits different market conditions. The adjustable parameters cater to different trading styles.
Risk Analysis
A price breakout beyond the grid bounds may cause severe losses. Parameters should be adjusted properly or combined with a stop loss to control risks. Also, excessive trading increases transaction costs.
Optimization Directions
Consider combining with a trend filter or optimizing grid parameters. A stop loss may also help prevent risks from extreme market moves.
Conclusion
This strategy systematically generates entries and exits while managing positions. Through parameter tuning it adapts to different preferences. It combines the rules-based nature of grid trading with the flexibility of trend trading, easing operation complexity while retaining robustness.
/*backtest
start: 2024-01-08 00:00:00
end: 2024-01-15 00:00:00
period: 5m
basePeriod: 1m
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

