
이 전략은 MACD, RSI, ADX 등 여러 동력 기술 지표를 통합하여 가격 역전 신호를 식별하고, 역전 전략을 적용하여 강력한 추세가 역전되면 역전 입장을 수행합니다. 이 전략은 수익을 잠금하고 위험을 제어하기 위해 simultaneously stop loss and stop stops를 설정합니다.
이 전략은 우선 MACD 지표의 빠른 느린 평균과 결합하여 금 포크 사다리 발생 여부를 판단하기 위해 가격 트렌드를 판단합니다. 그 다음은 RSI 지표와 결합하여 가짜 돌파구를 필터링하여 실제 가격 반전이 발생 한 후에 거래 신호를 생성합니다. 마지막으로 ADX 지표를 사용하여 가격이 트렌드 상태에 들어간 지 확인합니다. 위의 여러 조건이 동시에 충족 될 때만 구매 또는 판매 신호를 생성합니다.
구체적으로, MACD 패스트 라인에서 슬로우 라인을 통과하면 RSI가 50보다 높고 상승하면 ADX가 20보다 높으면 구매 신호입니다. MACD 패스트 라인에서 슬로우 라인을 통과하면 RSI가 50보다 낮고 떨어지면 ADX가 20보다 높으면 판매 신호입니다.
이 전략의 가장 큰 장점은 여러 지표를 사용하여 조합하여 진동 시가와 오류 신호를 효과적으로 필터링하여 트렌드 반전 지점을 실제로 잠금하여 높은 승률을 얻는 것입니다. 또한 수익을 잠금하고 위험을 제어하기 위해 스톱 손실을 설정하여 예기치 않은 사건의 영향을 효과적으로 방어 할 수 있습니다.
이 전략의 가장 큰 위험은 트렌드 반전 판단 오류, 예를 들어 가격의 심도 회귀가 잘못된 판단을 초래하는 것입니다. 또한, 반전 후의 새로운 추세는 충분한 이익을 얻기 위해 지속성이 없을 수 있습니다.
해결책은 더 많은 변수를 최적화하거나, 스톱 손실을 조정하거나, 더 많은 보조 지표와 결합하여 신호를 필터링하는 것입니다.
이 전략은 다음의 몇 가지 방향으로 더 개선될 수 있습니다.
MACD와 RSI의 조합을 최적화하여 가격 역전 판단의 정확성을 향상시킵니다.
KD, BOLL 등과 같은 더 많은 지표 필터를 추가하여 지표 주위 효과를 만듭니다.
동적으로 조정된 중지량, 시장 상황에 따라 조정
역전 후 실제 움직임에 따라 실시간으로 정지 위치를 수정합니다.
이 전략은 여러 가지 동적 지표를 통합하여 잠재적인 가격 반전 기회를 식별합니다. 매개 변수를 최적화하고, 더 많은 보조 지표를 조합하고, HST 전략을 동적으로 조정하면 전략의 안정성과 신뢰성을 더욱 높이고, 시장에서 제공하는 다양한 거래 기회를 잠금 할 수 있습니다.
/*backtest
start: 2023-11-28 00:00:00
end: 2023-12-28 00:00:00
period: 1h
basePeriod: 15m
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/
// © AHMEDABDELAZIZZIZO
//@version=5
strategy("Ta Strategy", overlay=true )
// inputs
inversestrategy = input.bool(false, title = "Inverse Strategy",tooltip = "This option makes you reverse the strategy so that long signals become where to short ")
direction = input.string(defval = "Both" , options = ["Both" , "Short" , "Long"] )
leftbars= input(6,title = " Left Bars" , group = "Support and resistance")
rightbars = input(6, title = " Right Bars", group = "Support and resistance")
macdfast = input(12, title = "MACD Fast", group = "MACD")
macdslow = input(26, title = "MACD Slow",group = "MACD")
macdsignal = input(7, "MACD Signal",group = "MACD")
sellqty = input(50, title = "QTY to sell at TP 1")
len = input(14, title="ADX Length" , group = "ADX")
// sup and res
res = fixnan(ta.pivothigh(high,leftbars,rightbars))
sup = fixnan(ta.pivotlow(low , leftbars,rightbars))
// macd
macd =ta.ema(close,macdfast) - ta.ema(close,macdslow)
signal=ta.ema(macd,macdsignal)
//adx
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
truerange = ta.rma(ta.tr,len)
plusDI = 100 * ta.rma(plusDM, len) / truerange
minusDI = 100 * ta.rma(minusDM, len) / truerange
dx = 100 * ta.rma(math.abs(plusDI - minusDI) / (plusDI + minusDI), len)
adx = ta.sma(dx, len)
// start deal condition
longcondition = ta.crossover(macd,signal) and close > res and ta.rsi(close,14) > 50 and plusDI > minusDI and adx > 20
shortcondition = ta.crossunder(macd,signal) and close < sup and ta.rsi(close,14) < 50 and plusDI < minusDI and adx > 20
//tp
longtp1 = input.float(6, "Long TP 1", minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100
longtp2 = input.float(12, "Long TP 2", minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100
longsl1 = input.float(3.0, "Long SL", minval = 0.0, step = 0.25, group = "Exit LONG Orders") /100
longtakeprofit1 = (strategy.position_avg_price * (1 + longtp1))
longstoploss1 = (strategy.position_avg_price * (1 - longsl1))
longtakeprofit2 = (strategy.position_avg_price * (1 + longtp2))
//sl
shorttp1 = input.float(6.0, "Short TP 1 ", minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100
shorttp2 = input.float(12.0, "Short TP 2", minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100
shortsl1 = input.float(3.0, "Short SL", minval = 0.0, step = 0.25, group = "Exit SHORT Orders")/100
shorttakeprofit1 = (strategy.position_avg_price * (1- shorttp1))
shortstoploss1 = (strategy.position_avg_price * (1 + shortsl1))
shorttakeprofit2 = (strategy.position_avg_price * (1- shorttp2))
//placeorders
if inversestrategy == false
if direction == "Both"
if longcondition and strategy.opentrades == 0
strategy.entry("long" , strategy.long )
strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)
strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)
if high >= longtakeprofit1
strategy.cancel("exit long 2")
strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)
if shortcondition and strategy.opentrades == 0
strategy.entry("short",strategy.short)
strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)
strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)
if low <= shorttakeprofit1
strategy.cancel("exit short 2")
strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)
else if direction == "Long"
if longcondition and strategy.opentrades == 0
strategy.entry("long" , strategy.long )
strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)
strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)
if high >= longtakeprofit1
strategy.cancel("exit long 2")
strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)
else if direction == "Short"
if shortcondition and strategy.opentrades == 0
strategy.entry("short",strategy.short)
strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)
strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)
if low <= shorttakeprofit1
strategy.cancel("exit short 2")
strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)
else
if direction == "Both"
if shortcondition and strategy.opentrades == 0
strategy.entry("long" , strategy.long )
strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)
strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)
if high >= longtakeprofit1
strategy.cancel("exit long 2")
strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)
if longcondition and strategy.opentrades == 0
strategy.entry("short",strategy.short)
strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)
strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)
if low <= shorttakeprofit1
strategy.cancel("exit short 2")
strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)
else if direction == "Long"
if shortcondition and strategy.opentrades == 0
strategy.entry("long" , strategy.long )
strategy.exit("exit long 1","long",qty_percent = sellqty ,limit = longtakeprofit1,stop = longstoploss1)
strategy.exit("exit long 2","long",qty_percent = 100 ,limit = longtakeprofit2,stop = longstoploss1)
if high >= longtakeprofit1
strategy.cancel("exit long 2")
strategy.exit("exit long 3","long",qty_percent = 100 ,limit = longtakeprofit2,stop = strategy.position_avg_price)
else if direction == "Short"
if longcondition and strategy.opentrades == 0
strategy.entry("short",strategy.short)
strategy.exit("exit short 1","short",qty_percent = sellqty ,limit = shorttakeprofit1,stop = shortstoploss1)
strategy.exit("exit short 2","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = shortstoploss1)
if low <= shorttakeprofit1
strategy.cancel("exit short 2")
strategy.exit("exit short 3","short",qty_percent = 100 ,limit = shorttakeprofit2,stop = strategy.position_avg_price)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
lsl1 = plot(strategy.position_size <= 0 ? na : longstoploss1, color=color.rgb(124, 11, 11), style=plot.style_linebr, linewidth=1)
ltp1 = plot(strategy.position_size <= 0 ? na : longtakeprofit1, color=color.rgb(15, 116, 18), style=plot.style_linebr, linewidth=1)
ltp2 = plot(strategy.position_size <= 0 ? na : longtakeprofit2, color=color.rgb(15, 116, 18), style=plot.style_linebr, linewidth=1)
avg = plot(strategy.position_avg_price, color=color.rgb(255, 153, 0, 47), style=plot.style_linebr, linewidth=1)
fill(ltp1,avg , color =strategy.position_size <= 0 ? na : color.rgb(82, 255, 97, 90))
fill(ltp2,ltp1 , color =strategy.position_size <= 0 ? na : color.rgb(82, 255, 97, 90))
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
ssl1 = plot(strategy.position_size >= 0 ? na : shortstoploss1, color=color.red, style=plot.style_linebr, linewidth=1)
stp1 = plot(strategy.position_size >= 0 ? na : shorttakeprofit2, color=color.green, style=plot.style_linebr, linewidth=1)
stp2 = plot(strategy.position_size >= 0 ? na : shorttakeprofit1, color=color.green, style=plot.style_linebr, linewidth=1)
fill(stp1,avg , color =strategy.position_size >= 0 ? na : color.rgb(30, 92, 35, 90))
fill(stp2,stp1 , color =strategy.position_size >= 0 ? na : color.rgb(30, 92, 35, 90))
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
resplot = plot(res, color=ta.change(res) ? na : #bf141446, linewidth=3, offset=-(rightbars+1), title="res")
supplot = plot(sup, color=ta.change(sup) ? na : #118f113a, linewidth=3, offset=-(rightbars+1), title="sup")