
この戦略は,Keltnerチャネル指標を移動平均と組み合わせて動的な突破買いと販売価格を設定し,低価格と高価格の突破操作を実現します. 戦略は,チャネル突破買いと販売の機会を自動的に識別します.
この戦略は,全体的に科学を合理的に使用し,ダイナミックチャネル指標によって価格の動きと方向を判断し,合理的なパラメータを設定し,突破信号をキャプチャし,低買い高売りを実現し,その結果,余分な利益を得ます.同時に,戦略のリスクを継続的に最適化し,複数の市場で安定的に動作できるようにします.
/*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")