Cette stratégie adopte le principe de l'écart de prix pour aller long lorsque le prix dépasse les plus bas récents, avec des ordres de stop loss et de prise de profit pour suivre le prix le plus bas pour la prise de profit.
Il identifie les écarts lorsque le prix tombe en dessous du prix le plus bas au cours des N dernières heures, va long basé sur un pourcentage configuré, avec des ordres de stop loss et de take profit.
Les avantages de cette stratégie:
Il y a aussi des risques:
La stratégie peut être améliorée dans les domaines suivants:
En conclusion, il s'agit d'une stratégie de stop loss simple et efficace basée sur les écarts de prix. Elle réduit efficacement les fausses entrées et les verrouillages des bénéfices. Il reste encore beaucoup de place pour des améliorations dans le réglage des paramètres et le filtrage des signaux. Il vaut la peine de poursuivre la recherche et le raffinement.
/*backtest start: 2022-11-21 00:00:00 end: 2023-11-27 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy(title="Squeeze Backtest by Shaqi v1.0", overlay=true, pyramiding=0, currency="USD", process_orders_on_close=true, commission_type=strategy.commission.percent, commission_value=0.075, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, backtest_fill_limits_assumption=0) strategy.risk.allow_entry_in(strategy.direction.long) R0 = "6 Hours" R1 = "12 Hours" R2 = "24 Hours" R3 = "48 Hours" R4 = "1 Week" R5 = "2 Weeks" R6 = "1 Month" R7 = "Maximum" buyPercent = input( title="Buy, %", type=input.float, defval=3, minval=0.01, step=0.01, inline="Percents", group="Squeeze Settings") * 0.01 sellPercent = input(title="Sell, %", type=input.float, defval=1, minval=0.01, step=0.01, inline="Percents", group="Squeeze Settings") * 0.01 stopPercent = input(title="Stop Loss, %", type=input.float, defval=1, minval=0.01, maxval=100, step=0.01, inline="Percents", group="Squeeze Settings") * 0.01 isMaxBars = input( title="Max Bars To Sell", type=input.bool, defval=true , inline="MaxBars", group="Squeeze Settings") maxBars = input( title="", type=input.integer, defval=2, minval=0, maxval=1000, step=1, inline="MaxBars", group="Squeeze Settings") bind = input( title="Bind", type=input.source, defval=close, group="Squeeze Settings") isRange = input( title="Fixed Range", type=input.bool, defval=true, inline="Range", group="Backtesting Period") rangeStart = input( title="", defval=R4, options=[R0, R1, R2, R3, R4, R5, R6, R7], inline="Range", group="Backtesting Period") periodStart = input(title="Backtesting Start", type=input.time, defval=timestamp("01 Aug 2021 00:00 +0000"), group="Backtesting Period") periodEnd = input( title="Backtesting End", type=input.time, defval=timestamp("01 Aug 2022 00:00 +0000"), group="Backtesting Period") int startDate = na int endDate = na if isRange if rangeStart == R0 startDate := timenow - 21600000 endDate := timenow else if rangeStart == R1 startDate := timenow - 43200000 endDate := timenow else if rangeStart == R2 startDate := timenow - 86400000 endDate := timenow else if rangeStart == R3 startDate := timenow - 172800000 endDate := timenow else if rangeStart == R4 startDate := timenow - 604800000 endDate := timenow else if rangeStart == R5 startDate := timenow - 1209600000 endDate := timenow else if rangeStart == R6 startDate := timenow - 2592000000 endDate := timenow else if rangeStart == R7 startDate := time endDate := timenow else startDate := periodStart endDate := periodEnd afterStartDate = (time >= startDate) beforeEndDate = (time <= endDate) notInTrade = strategy.position_size == 0 inTrade = strategy.position_size > 0 barsFromEntry = barssince(strategy.position_size[0] > strategy.position_size[1]) entry = strategy.position_size[0] > strategy.position_size[1] entryBar = barsFromEntry == 0 notEntryBar = barsFromEntry != 0 buyLimitPrice = bind - bind * buyPercent buyLimitFilled = low <= buyLimitPrice sellLimitPriceEntry = buyLimitPrice * (1 + sellPercent) sellLimitPrice = strategy.position_avg_price * (1 + sellPercent) stopLimitPriceEntry = buyLimitPrice - buyLimitPrice * stopPercent stopLimitPrice = strategy.position_avg_price - strategy.position_avg_price * stopPercent if afterStartDate and beforeEndDate and notInTrade strategy.entry("BUY", true, limit = buyLimitPrice) strategy.exit("INSTANT", limit = sellLimitPriceEntry, stop = stopLimitPriceEntry) strategy.cancel("INSTANT", when = inTrade) if isMaxBars strategy.close("BUY", when = barsFromEntry >= maxBars, comment = "Don't Sell") strategy.exit("SELL", limit = sellLimitPrice, stop = stopLimitPrice) showStop = stopPercent <= 0.03 plot(showStop ? stopLimitPrice : na, title="Stop Loss Limit Order", style=plot.style_linebr, color=color.red, linewidth=1) plot(sellLimitPrice, title="Take Profit Limit Order", style=plot.style_linebr, color=color.purple, linewidth=1) plot(strategy.position_avg_price, title="Buy Order Filled Price", style=plot.style_linebr, color=color.blue, linewidth=1) plot(buyLimitPrice, title="Trailing Buy Limit Order", style=plot.style_stepline, color=color.new(color.blue, 30), offset=1)