
Chiến lược này sử dụng chỉ số Keltner Channel, kết hợp với đường trung bình di chuyển, thiết lập giá mua và bán phá vỡ động, thực hiện các hoạt động phá vỡ mua và bán thấp. Chiến lược có thể tự động xác định cơ hội mua và bán phá vỡ kênh.
Chiến lược này sử dụng khoa học hợp lý tổng thể, thông qua chỉ số kênh động để đánh giá xu hướng và hướng giá, đặt tham số hợp lý để bắt tín hiệu đột phá, thực hiện mua thấp và bán cao, và sau đó thu được lợi nhuận vượt trội. Đồng thời, chiến lược rủi ro được tối ưu hóa liên tục để có thể hoạt động ổn định trong nhiều thị trường.
/*backtest
start: 2024-01-27 00:00:00
end: 2024-02-26 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title="Keltner Strategy", overlay=true)
length = input.int(20, minval=1)
mult = input.float(2.0, "Multiplier")
src = input(close, title="Source")
exp = input(true, "Use Exponential MA")
BandsStyle = input.string("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style")
atrlength = input(10, "ATR Length")
esma(source, length)=>
s = ta.sma(source, length)
e = ta.ema(source, length)
exp ? e : s
ma = esma(src, length)
rangema = BandsStyle == "True Range" ? ta.tr(true) : BandsStyle == "Average True Range" ? ta.atr(atrlength) : ta.rma(high - low, length)
upper = ma + rangema * mult
lower = ma - rangema * mult
crossUpper = ta.crossover(src, upper)
crossLower = ta.crossunder(src, lower)
bprice = 0.0
bprice := crossUpper ? high+syminfo.mintick : nz(bprice[1])
sprice = 0.0
sprice := crossLower ? low -syminfo.mintick : nz(sprice[1])
crossBcond = false
crossBcond := crossUpper ? true
: na(crossBcond[1]) ? false : crossBcond[1]
crossScond = false
crossScond := crossLower ? true
: na(crossScond[1]) ? false : crossScond[1]
cancelBcond = crossBcond and (src < ma or high >= bprice )
cancelScond = crossScond and (src > ma or low <= sprice )
if (cancelBcond)
strategy.cancel("KltChLE")
if (crossUpper)
strategy.entry("KltChLE", strategy.long, stop=bprice, comment="KltChLE")
if (cancelScond)
strategy.cancel("KltChSE")
if (crossLower)
strategy.entry("KltChSE", strategy.short, stop=sprice, comment="KltChSE")