
La stratégie est un système de négociation bidirectionnel basé sur une ligne K de 30 minutes pour rechercher des opportunités de négociation en surveillant l’amplitude des fluctuations des prix. Le cœur de la stratégie est d’identifier les fluctuations importantes en définissant des seuils ponctuels et de négocier dans la direction correspondante après la confirmation de la rupture.
La stratégie utilise un mécanisme de filtrage multiple pour identifier les signaux de négociation efficaces. Tout d’abord, la stratégie calcule l’amplitude de fluctuation de l’entité à la clôture de la ligne K toutes les 30 minutes. Lorsque l’amplitude de la fluctuation dépasse la limite prédéfinie, elle est marquée comme une opportunité de négociation potentielle.
Il s’agit d’une stratégie de trading automatisée entièrement conçue et logiquement claire. Grâce à un filtrage conditionnel et à un contrôle des risques rigoureux, la stratégie a une bonne praticité. Cependant, il est nécessaire de tester et d’optimiser suffisamment sur le terrain, en particulier en ce qui concerne le paramétrage et le contrôle des risques.
/*backtest
start: 2024-10-01 00:00:00
end: 2024-10-31 23:59:59
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Big Candle Breakout Strategy Both Side", overlay=true)
// Input for the point move threshold
point_move_in = input.int(100, title="Point Move Threshold")
point_target = input.int(100, title="Point Target")
point_stoploss = input.int(100, title="Point Stop Loss")
point_buffer = input.int(5, title="Point Buffer")
point_move = point_buffer + point_move_in
// Define the start and end times for trading
start_hour = 9
start_minute = 15
end_hour = 14
end_minute = 30
// Function to check if the current time is within the allowed trading window
in_time_range = (hour(time('30')) > start_hour or (hour(time('30')) == start_hour and minute(time('30')) >= start_minute)) and (hour(time('30')) < end_hour or (hour(time('30')) == end_hour and minute(time('30')) <= end_minute))
// Retrieve the open, high, low, and close prices of 30-minute candles
open_30m = request.security(syminfo.tickerid, "30", open)
high_30m = request.security(syminfo.tickerid, "30", high)
low_30m = request.security(syminfo.tickerid, "30", low)
close_30m = request.security(syminfo.tickerid, "30", close)
// Calculate the range of the candle
candle_range_long = (close_30m - open_30m)
candle_range_short = (open_30m - close_30m)
// Determine if the candle meets the criteria to be marked
big_candle_long = candle_range_long >= point_move_in
big_candle_short = candle_range_short >= point_move_in
// Variables to store the state of the trade
var float long_entry_price = na
var float long_target_price = na
var float long_stop_loss_price = na
var float short_entry_price = na
var float short_target_price = na
var float short_stop_loss_price = na
// Check if there are no active trades
no_active_trades = (strategy.opentrades == 0)
// Long entry condition
if (big_candle_long and na(long_entry_price) and in_time_range and no_active_trades)
long_entry_price := high_30m+point_buffer
long_target_price := long_entry_price + point_target
long_stop_loss_price := long_entry_price - point_stoploss
strategy.entry("Buy", strategy.long, stop=long_entry_price, limit=long_target_price)
plot(long_entry_price, style=plot.style_linebr, color=color.blue, linewidth=2, title="Entry Price")
plot(long_target_price, style=plot.style_linebr, color=color.green, linewidth=2, title="Target Price")
plot(long_stop_loss_price, style=plot.style_linebr, color=color.red, linewidth=2, title="Stop Loss Price")
// Short entry condition
if (big_candle_short and na(short_entry_price) and in_time_range and no_active_trades)
short_entry_price := low_30m - point_buffer
short_target_price := short_entry_price - point_target
short_stop_loss_price := short_entry_price + point_stoploss
strategy.entry("Sell", strategy.short, stop=short_entry_price, limit=short_target_price)
plot(short_entry_price, style=plot.style_linebr, color=color.blue, linewidth=2, title="Short Entry Price")
plot(short_target_price, style=plot.style_linebr, color=color.green, linewidth=2, title="Short Target Price")
plot(short_stop_loss_price, style=plot.style_linebr, color=color.red, linewidth=2, title="Short Stop Loss Price")
// Long exit conditions
if (not na(long_entry_price))
strategy.exit("Long Exit", from_entry="Buy", limit=long_target_price, stop=long_stop_loss_price)
// Short exit conditions
if (not na(short_entry_price))
strategy.exit("Short Exit", from_entry="Sell", limit=short_target_price, stop=short_stop_loss_price)
// Reset trade status
if (strategy.position_size == 0)
long_entry_price := na
long_target_price := na
long_stop_loss_price := na
short_entry_price := na
short_target_price := na
short_stop_loss_price := na
// Plot the big candle and entry/exit levels
plotshape(series=big_candle_long, location=location.abovebar, style=shape.circle, color=color.green)
plotshape(series=big_candle_short, location=location.abovebar, style=shape.circle, color=color.red)
//plot(long_entry_price, style=plot.style_stepline, color=color.blue, linewidth=2, title="Entry Price")
//plot(long_target_price, style=plot.style_stepline, color=color.green, linewidth=2, title="Target Price")
//plot(long_stop_loss_price, style=plot.style_stepline, color=color.red, linewidth=2, title="Stop Loss Price")