
Chiến lược này giao dịch khi đáp ứng các điều kiện cụ thể bằng cách sử dụng các chỉ số như đường trung bình di chuyển phẳng (SMA), chỉ số tương đối mạnh (RSI), phạm vi thực (TR) và đường trung bình di chuyển khối lượng giao dịch (Volume MA), kết hợp với bộ lọc xu hướng, khối lượng giao dịch và điều kiện biến động. Ý tưởng chính của chiến lược này là mua khi giá thấp hơn SMA200 và đang trong xu hướng giảm, khối lượng giao dịch thấp và biến động thấp, và đặt lệnh dừng và dừng.
Chiến lược này có thể kiểm soát rủi ro một cách hiệu quả bằng cách sử dụng tổng hợp nhiều chỉ số kỹ thuật, kết hợp lọc xu hướng và khối lượng giao dịch, điều kiện biến động, trong trường hợp cụ thể. Đồng thời, thiết lập các cơ chế dừng lỗ và thoát ngoại lệ rõ ràng, có thể kiểm soát rủi ro hiệu quả. Tuy nhiên, chiến lược này cũng có một số hạn chế, các yếu tố như lựa chọn tham số, thị trường bất thường có thể ảnh hưởng đến hiệu suất của chiến lược.
/*backtest
start: 2024-05-01 00:00:00
end: 2024-05-31 23:59:59
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Strategia Stop Loss & Take Profit z Filtrem Trendu i Wyjątkiem", shorttitle="Smooth MA SL & TP with Exception", overlay=true)
// Parametry
tp_multiplier = input.float(1.5, title="Mnożnik Take Profit")
sl_percent = input.float(5, title="Procent Stop Loss")
wait_bars = input.int(3, title="Liczba Oczekiwanych Świec")
sma_period = input.int(200, title="Okres SMA")
rsi_period = input.int(14, title="Okres RSI")
vol_ma_period = input.int(20, title="Okres Średniej Wolumenu")
tr_ma_period = input.int(20, title="Okres Średniej Rzeczywistego Zakresu")
// Obliczenie Gładkiej Średniej Kroczącej
sma = ta.sma(close, sma_period)
// Obliczenie RSI
rsi = ta.rsi(close, rsi_period)
// Filtr Trendu
uptrend = close > sma
downtrend = close < sma
// Warunek konsolidacji: Niski wolumen i niska zmienność
niski_wolumen = volume < ta.sma(volume, vol_ma_period)
niska_zmienosc = ta.tr(true) < ta.sma(ta.tr(true), tr_ma_period)
// Warunek Wejścia (Long): Cena poniżej SMA 200 i filtr trendu w strefie czerwonej
warunek_wejscia = close < sma and niski_wolumen and niska_zmienosc and not uptrend
// Warunek Wyjścia ze strategii
warunek_wyjscia = downtrend and close > sma and ta.crossover(close, sma)
// Ustalanie Stop Loss i Take Profit
var float stop_loss = na
var float take_profit = na
var int indeks_wejscia = na
if (warunek_wejscia)
stop_loss := close * (1 - sl_percent / 100)
take_profit := close * (1 + tp_multiplier)
indeks_wejscia := bar_index
// Handel
if (warunek_wejscia)
strategy.entry("Long", strategy.long)
// Warunek Wyjścia: RSI w strefie wykupienia lub Stop Loss/Take Profit
if (strategy.opentrades != 0)
if (rsi > 70)
strategy.exit("Take Profit/Stop Loss", "Long", limit=take_profit)
else if (bar_index - indeks_wejscia == wait_bars)
strategy.exit("Take Profit/Stop Loss", "Long", stop=stop_loss, limit=take_profit)
// Wyjątek: Warunek Wyjścia z Longów na podstawie zmiany trendu
if (warunek_wyjscia)
strategy.close("Long")
// Rysowanie RSI
rsi_plot = plot(rsi, title="RSI", color=color.blue)
// Rysowanie Gładkiej Średniej Kroczącej
sma_plot = plot(sma, color=color.gray, title="Smooth MA", linewidth=2)
// Rysowanie Filtru Trendu
fill(sma_plot, rsi_plot, color=downtrend ? color.new(color.red, 90) : na)