The strategy mainly detects the breakthrough of the box formed by the high and low points of K-line to judge the direction and strength of the market. When there is an upward box breakout, the strategy will set a long position around the breakout point. When there is a downward box breakout, the strategy will set a short position around the breakout point. Once a trading signal is generated, the strategy will place orders to open positions and set stop loss and take profit to control risks.
The strategy defines a trading time period and only looks for trading opportunities during that period.
After each K-line forms, the strategy judges whether there is a significant breakthrough between the highest and lowest prices of the previous two K-lines.
2.1 If the lowest price of the 2nd K-line is higher than the highest price of the 1st K-line, there is an upward box breakout.
2.2 If the highest price of the 2nd K-line is lower than the lowest price of the 1st K-line, there is a downward box breakout.
After confirming the box breakout signal, the strategy sets a long or short entry point around the highest or lowest price of the current K-line.
Once the position is opened, the strategy sets the take profit based on twice the breakout range to capture trend acceleration.
The strategy also sets the stop loss at the lowest or highest price of the 2nd K-line to reduce loss risk.
The strategy has the following advantages:
The logic is simple and easy to implement.
Using K-line box breakouts to judge market direction and strength has high accuracy.
The take profit setting captures opportunities from trend acceleration. The multiplier is adjustable.
There is a clear stop loss logic to control single loss.
The strategy idea is flexible and can be customized according to personal style.
However, there are some risks in the strategy:
Breakout signals may be false breakouts, losses cannot be completely avoided.
The stop loss near the entry point can be easily triggered by aggressive markets.
It cannot judge the trend structure and stops may be frequently triggered in range-bound markets.
It does not consider the impact of different products and time periods.
To further optimize the strategy, we can improve from the following aspects:
Set adaptive stop loss and take profit parameters for different products and time periods.
Add technical indicators for trend judgment to avoid being trapped in range-bound markets.
Set subsequent add-on opportunities to track trend runs.
Combine volume indicators to judge the authenticity of breakouts and filter signals.
Add machine learning algorithms to assist in determining trend direction.
The strategy is designed based on the simple breakout principle to capture accelerated runs after breakouts for excess returns. It uses stops and profits to control risks. The easy-to-understand and implement strategy can be customized and optimized according to personal needs and market environments, making it highly practical.
/*backtest start: 2024-01-07 00:00:00 end: 2024-01-14 00:00:00 period: 3m basePeriod: 1m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Dvitash //@version=5 strategy("Casper SMC Silver Bullet", shorttitle = "Casper SB", overlay=true, calc_on_order_fills = true) startTime = input(defval = "1000", title = "Start Time") endTime = input(defval = "1600", title = "End Time") contractAmt = input.int(defval = 2, title = "Contract Amount") fvgCol = input.color(defval = color.rgb(63, 61, 179, 41), title = "FVG Color") borderCol = input.color(defval = color.rgb(35, 33, 172, 41), title = "FVG Border Color") fvgExtendLength = input.int(defval = 0, minval = 0, title = "FVG Extend Length") allowedTime = not na(time(timeframe.period, startTime + "-" + endTime +":23456", "America/New_York")) newDay = bool(ta.change(time('D'))) h = hour(time('1'), "America/New_York") var bool fvgDrawn = na var float entryPrice = na var float stopPrice = na var float tpPrice = na if newDay fvgDrawn := false // a_allBoxes = box.all // if array.size(a_allBoxes) > 0 // for i = 0 to array.size(a_allBoxes) - 1 // box.delete(array.get(a_allBoxes, i)) if allowedTime and barstate.isconfirmed and h <= 16 //Long FVG if high[2] < low and not fvgDrawn // box.new(bar_index[2], low, bar_index + fvgExtendLength, high[2], bgcolor = fvgCol, border_color = borderCol) stopPrice := low[2] entryPrice := low tpPrice := entryPrice + (math.abs(low[2] - entryPrice) * 2) // log.info("SL: " + str.tostring(stopPrice) + " Entry: " + str.tostring(entryPrice) + " TP: " + str.tostring(tpPrice)) strategy.entry("long", strategy.long, contractAmt, limit = entryPrice, comment = "Long Entry") fvgDrawn := true if low[2] > high and not fvgDrawn // box.new(bar_index[2], high, bar_index + fvgExtendLength, low[2], bgcolor = fvgCol, border_color = borderCol) stopPrice := high[2] entryPrice := high tpPrice := entryPrice - (math.abs(high[2] - entryPrice) * 2) // log.info("SL: " + str.tostring(stopPrice) + " Entry: " + str.tostring(entryPrice) + " TP: " + str.tostring(tpPrice)) strategy.entry("short", strategy.short, contractAmt, limit = entryPrice, comment = "Short Entry") fvgDrawn := true if h >= 16 strategy.close_all() strategy.cancel_all() strategy.exit("long exit", from_entry = "long", qty = contractAmt, limit = tpPrice, stop = stopPrice, comment = "Long Exit") strategy.exit("short exit", from_entry = "short", qty = contractAmt, limit = tpPrice, stop = stopPrice, comment = "Short Exit")