
Chiến lược bouncing moving average là một chiến lược theo dõi giá phá vỡ đường trung bình di chuyển. Nó kiểm tra xem con dao có quay trở lại từ phía dưới đường trung bình di chuyển hay không, nếu vậy, đó là tín hiệu đa đầu; nếu con dao quay trở lại từ phía trên đường trung bình di chuyển, đó là tín hiệu đầu không.
Exponential Moving Average Bounce Strategy
Chiến lược này dựa trên đường trung bình di chuyển theo cấp số nhân. Nó sẽ tính toán một đường EMA trong thời gian thực. Sau đó kiểm tra xem giá có bật lên hoặc xuống dưới đường EMA hay không:
Một sự phản hồi như vậy là tín hiệu đầu tiên cho chiến lược.
Chiến lược phản hồi của EMA chỉ được đưa vào thị trường sau khi xác định giá đã đảo ngược, để tránh hoạt động ngược trở lại.
Do sử dụng chỉ số di chuyển trung bình, có thể làm mịn dữ liệu giá một cách hiệu quả, lọc tiếng ồn thị trường, làm cho chiến lược này trở lại nhỏ và lợi nhuận lịch sử tốt hơn.
Chiến lược EMA rebound chỉ dựa vào moving average, rất đơn giản và dễ hiểu cho người mới; đồng thời các tham số EMA chu kỳ có thể được điều chỉnh linh hoạt để phù hợp với các giống khác nhau.
Gần các đường EMA thường có các đột phá giả dày đặc, có thể gây ra tín hiệu sai. Cần điều chỉnh tham số EMA để lọc những tiếng ồn này.
Chiến lược này về cơ bản là hoạt động theo chiều hướng. Không thể dự đoán được điểm biến động giá, chỉ có thể theo xu hướng. Đây có thể là thời điểm nhập cảnh tốt nhất để bỏ lỡ điều chỉnh chu kỳ.
Các mức dừng gần đường trung bình di chuyển đôi khi bị phá vỡ, gây ra sự mất mát lớn hơn. Điều này đòi hỏi phải sử dụng các phương pháp dừng linh hoạt hơn.
Các chỉ số khác như RSI, MACD và các chỉ số khác có thể được thêm vào để xác nhận sự đảo ngược giá, lọc các tín hiệu giả.
Có thể sử dụng các phương pháp dừng lỗ linh hoạt hơn như dừng thời gian, dừng rung, để giảm nguy cơ bị đâm.
Tối ưu hóa các tham số EMA chu kỳ để tìm ra sự kết hợp tham số tốt nhất. Bạn cũng có thể làm cho các tham số EMA thay đổi động, theo dõi chu kỳ thị trường.
Chiến lược phản hồi đường trung bình di chuyển là một chiến lược theo dõi xu hướng đơn giản và thực tế. Nó hoạt động theo chiều hướng, rút lui nhỏ, dễ hiểu. Ngoài ra, có một số rủi ro tín hiệu giả và rủi ro dừng. Chúng ta có thể tối ưu hóa chiến lược này bằng cách kết hợp các chỉ số tốt hơn, cách dừng và lựa chọn tham số, làm cho nó trở thành một chiến lược định lượng ổn định và đáng tin cậy.
/*backtest
start: 2022-12-01 00:00:00
end: 2023-12-07 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tweakerID
// Simple strategy that checks for price bounces over an Exponential Moving Average. If the CLOSE of the candle bounces
// back from having it's LOW below the EMA, then it's a Bull Bounce. If the CLOSE of the candle bounces down from having it's
// high above the EMA, then it's a Bear Bounce. This logic can be reverted.
//@version=4
strategy("EMA Bounce", overlay=true,
default_qty_type=strategy.percent_of_equity,
default_qty_value=100,
initial_capital=10000,
commission_value=0.04,
calc_on_every_tick=false,
slippage=0)
direction = input(0, title = "Strategy Direction", type=input.integer, minval=-1, maxval=1)
strategy.risk.allow_entry_in(direction == 0 ? strategy.direction.all : (direction < 0 ? strategy.direction.short : strategy.direction.long))
/////////////////////// STRATEGY INPUTS ////////////////////////////////////////
title1=input(true, "-----------------Strategy Inputs-------------------")
i_EMA=input(20, title="EMA Length")
/////////////////////// BACKTESTER /////////////////////////////////////////////
title2=input(true, "-----------------General Inputs-------------------")
// Backtester General Inputs
i_SL=input(true, title="Use Swing Stop Loss and Take Profit")
i_SPL=input(defval=10, title="Swing Point Loopback")
i_PercIncrement=input(defval=.2, step=.1, title="Swing Point SL Perc Increment")*0.01
i_TPRRR = input(1.2, step=.1, title="Take Profit Risk Reward Ratio")
// Bought and Sold Boolean Signal
bought = strategy.position_size > strategy.position_size[1]
or strategy.position_size < strategy.position_size[1]
// Price Action Stop and Take Profit
LL=(lowest(i_SPL))*(1-i_PercIncrement)
HH=(highest(i_SPL))*(1+i_PercIncrement)
LL_price = valuewhen(bought, LL, 0)
HH_price = valuewhen(bought, HH, 0)
entry_LL_price = strategy.position_size > 0 ? LL_price : na
entry_HH_price = strategy.position_size < 0 ? HH_price : na
tp=strategy.position_avg_price + (strategy.position_avg_price - entry_LL_price)*i_TPRRR
stp=strategy.position_avg_price - (entry_HH_price - strategy.position_avg_price)*i_TPRRR
/////////////////////// STRATEGY LOGIC /////////////////////////////////////////
EMA=ema(close, i_EMA)
LowAboveEMA=low > EMA
LowBelowEMA=low < EMA
HighAboveEMA=high > EMA
HighBelowEMA=high < EMA
BullBounce=LowAboveEMA[1] and LowBelowEMA and close > EMA //and close > open
BearBounce=HighBelowEMA[1] and HighAboveEMA and close < EMA //and close < open
plot(EMA)
BUY=BullBounce
SELL=BearBounce
//Inputs
DPR=input(false, "Allow Direct Position Reverse")
reverse=input(false, "Reverse Trades")
// Entries
if reverse
if not DPR
strategy.entry("long", strategy.long, when=SELL and strategy.position_size == 0)
strategy.entry("short", strategy.short, when=BUY and strategy.position_size == 0)
else
strategy.entry("long", strategy.long, when=SELL)
strategy.entry("short", strategy.short, when=BUY)
else
if not DPR
strategy.entry("long", strategy.long, when=BUY and strategy.position_size == 0)
strategy.entry("short", strategy.short, when=SELL and strategy.position_size == 0)
else
strategy.entry("long", strategy.long, when=BUY)
strategy.entry("short", strategy.short, when=SELL)
SL=entry_LL_price
SSL=entry_HH_price
TP=tp
STP=stp
strategy.exit("TP & SL", "long", limit=TP, stop=SL, when=i_SL)
strategy.exit("TP & SL", "short", limit=STP, stop=SSL, when=i_SL)
/////////////////////// PLOTS //////////////////////////////////////////////////
plot(strategy.position_size > 0 ? SL : na , title='SL', style=plot.style_cross, color=color.red)
plot(strategy.position_size < 0 ? SSL : na , title='SSL', style=plot.style_cross, color=color.red)
plot(strategy.position_size > 0 ? TP : na, title='TP', style=plot.style_cross, color=color.green)
plot(strategy.position_size < 0 ? STP : na, title='STP', style=plot.style_cross, color=color.green)
// Draw price action setup arrows
plotshape(BUY ? 1 : na, style=shape.triangleup, location=location.belowbar,
color=color.green, title="Bullish Setup", transp=80, size=size.auto)
plotshape(SELL ? 1 : na, style=shape.triangledown, location=location.abovebar,
color=color.red, title="Bearish Setup", transp=80, size=size.auto)