
이 전략은 카우프만 적응 이동 평균 (KAMA) 에 기반하여 거래 포지션을 동적으로 조정하고 시장 추세를 자동으로 추적할 수 있습니다. 전략의 주요 기능은 다음과 같습니다.
이러한 기능을 통해, 전략은 트렌드의 추가적인 수익을 얻고, 동시에 위험을 통제하려고 한다.
이 전략은 카우프만 (Kaufman) 의 자율적 이동 평균 지표 작업에 기초한다. KAMA는 가격 운동량과 변동률의 비율을 계산하여 평균의 무게와 부드러움을 동적으로 조정하여 가격 변화에 더 빠르게 반응한다.
KAMA 상의 하향 스톱 라인을 통과하면 트렌드가 반전되어 구매 신호가 발생하고 KAMA 아래의 하향 스톱 라인을 통과하면 트렌드가 반전되어 판매 신호가 발생합니다. 포지션에 진입 한 후, 전략은 ATR에 따라 동적인 스톱 거리를 계산하고 스톱 라인을 설정합니다. KAMA가 유리한 방향으로 이동하면 스톱 라인이 따라 조정되어 더 많은 이익을 잠금하기 위해 스톱 라인을 유리한 위치로 이동합니다.
이렇게하면, 전략은 트렌드를 추적하고, 서서히 스톱 라인을 움직여서 스톱 라인이 트리플되거나 반전 신호가 트리플되어서 평형할 수 있다.
전통적인 이동 평균 전략에 비해 이 전략은 다음과 같은 장점이 있습니다.
전체적으로 보면, 전략은 빠르게 반응하고, 통제가능하며, 전형적인 트렌드 추적 전략이다.
이 전략에는 몇 가지 위험도 있습니다.
이러한 위험에 대해, 절감 손실 거리를 최적화, 최대 절감 손실 비율을 설정하는 방법과 같은 방법을 통해 제어 할 수 있습니다. 또한 다른 지표와 결합하여 확인하여 잘못된 거래를 방지 할 수 있습니다.
이 전략의 최적화 방향은 다음과 같습니다.
예를 들어, KAMA 골드포크와 동시에 MACDif가 긍정적이고 확장되도록 요구되는 보조 확인 지표로 MACD를 추가하는 테스트를 수행 할 수 있습니다. 이것은 몇 가지 가짜 신호를 필터링하여 불필요한 반복적인 포지션을 피 할 수 있습니다.
이 전략은 전체적으로 원활하게 작동하며, 동적 스톱로스를 사용하여 트렌드를 추적하고, 트렌드 수익을 최대한 고정합니다. KAMA 지표의 적응성은 전략이 시장의 급격한 변화에 따라 움직일 수 있도록합니다. 약간의 최적화를 통해 전략은 중장선 운영에 적합한 효율적인 트렌드 추적 프로그램이 될 수 있습니다.
/*backtest
start: 2024-01-26 00:00:00
end: 2024-02-25 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("THMA - Bharath Vc Improved", overlay=true, process_orders_on_close=true)
// Function to calculate pips with higher precision
getPips(price) =>
difc = syminfo.mintick
hlpips = price / difc
math.round(hlpips / syminfo.mintick) * syminfo.mintick
// Inputs
buyMess = input.string("Buy Message","Buy Alert Message")
sellMess = input.string("Sell Message","Sell Alert Message")
buyExitMessage = input.string("Buy Exit","Buy Exit Alert Message" )
sellExitMessage = input.string("Sell Exit","Sell Exit Alert Message" )
tmf = input.timeframe("", "Timeframe")
length = input(title='Length', defval=14)
fastLength = input(title='Fast EMA Length', defval=2)
slowLength = input(title='Slow EMA Length', defval=30)
src = input(title='Source', defval=close)
highlight = input(title='Highlight ?', defval=true)
awaitBarConfirmation = input(title='Await Bar Confirmation ?', defval=true)
// Function to calculate the TMA
gettma() =>
mom = math.abs(ta.change(src, length))
volatility = math.sum(math.abs(ta.change(src)), length)
er = volatility != 0 ? mom / volatility : 0
fastAlpha = 2 / (fastLength + 1)
slowAlpha = 2 / (slowLength + 1)
alpha = math.pow(er * (fastAlpha - slowAlpha) + slowAlpha, 2)
kama = 0.0
kama := alpha * src + (1 - alpha) * nz(kama[1], src)
await = awaitBarConfirmation ? barstate.isconfirmed : true
maColor = highlight ? kama > kama[1] and await ? color.green : color.red : color.new(color.purple, 0)
thma = kama
hma_dif = (thma - thma[2])/2
colour = hma_dif > 0 ? color.green : color.red
isGreen = hma_dif > 0
[thma, isGreen, colour]
// Dynamic pip size based on ATR to adapt better to smaller timeframes
pips = ta.atr(14) * 0.1
// Main execution logic
var float psl = na
var int lastSignal = 0
var float lastPsl = na
[thma, isGreen, colour] = request.security(syminfo.tickerid, tmf, gettma(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
plot(thma, title='KAMA', linewidth=2, color=colour)
if ta.crossover(thma, psl) and strategy.position_size < 0
strategy.exit("Sell Exit", stop=thma, alert_message=sellExitMessage)
if ta.crossunder(thma, psl) and strategy.position_size > 0
strategy.exit("Buy Exit", stop=thma, alert_message=buyExitMessage)
if isGreen and strategy.position_size <= 0
if na(psl)
psl := close + getPips(pips)
strategy.entry("Buy", strategy.long, alert_message=buyMess)
lastSignal := 1
if not isGreen and strategy.position_size >= 0
if na(psl)
psl := close - getPips(pips)
strategy.entry("Sell", strategy.short, alert_message=sellMess)
lastSignal := -1
if (thma >= lastPsl or na(lastPsl)) and thma > psl
psl := psl + getPips(pips)
lastPsl := psl
if (thma <= lastPsl or na(lastPsl)) and thma < psl
psl := psl - getPips(pips)
lastPsl := psl
plot(psl, title="Position Stop Level", style=plot.style_stepline, color=color.blue)
plot(lastPsl, title="Last Position Stop Level", style=plot.style_cross, color=color.red)