슈퍼트렌드 글링 전략

저자:차오장, 날짜: 2023-12-08 15:40:26
태그:

img

전반적인 설명

슈퍼트렌드 앙글핑 전략은 트렌드 패턴이 트렌드를 확인할 때 트렌드 방향을 파악하고 좋은 리스크-어워드 비율 진입 기회를 찾기 위해 평균 진정한 범위 (ATR), 슈퍼트렌드 지표 및 앙글핑 패턴을 결합하는 트렌드 다음 전략입니다.

전략 논리

이 전략은 먼저 ATR 및 SuperTrend 지표를 사용하여 현재 시장 트렌드 방향을 결정합니다. 구체적으로, 가격이 상단보다 낮을 때 하향 트렌드가 정의되며 가격이 하단보다 높을 때 상승 트렌드가 정의됩니다.

동시에, 전략은 K-라인이 흡수 패턴을 형성하는지 여부를 판단합니다. 코드 논리에 따르면, 상승 추세에서, 이전 바의 폐쇄 가격이 현재 바의 오픈 가격보다 높고, 현재 바의 폐쇄 가격이 오픈 가격보다 낮으면 상승 추세가 유발됩니다. 하락 추세에서, 이전 바의 폐쇄 가격이 현재 바의 오픈 가격보다 낮고, 현재 바의 폐쇄 가격이 오픈 가격보다 높으면 하락 추세가 유발됩니다.

포식 패턴이 트렌드 방향과 일치하면 거래 신호가 생성됩니다. 또한 전략은 포식 패턴에 따라 스톱 로스를 계산하고 수익 수준을 취합니다. 시장에 진출한 후 가격이 스톱 로스 또는 수익 수준을 만지면 현재 위치가 종료됩니다.

이점 분석

이 전략은 트렌드 추적 및 패턴 인식의 장점을 결합하여 트렌드 시장에서 반전 신호를 식별하여 전환점에 더 큰 움직임을 잡습니다. 또한, 중지 손실 메커니즘은 손실 위험을 효과적으로 제어 할 수 있습니다.

위험 분석

이 전략의 가장 큰 위험은 포괄 패턴이 가짜 브레이크가 될 수 있으며, 따라서 잘못된 신호를 생성 할 수 있다는 것입니다. 또한, 스톱 로스 및 수익 취득 설정도 너무 임의적 인 것으로 균형 잡힌 이익과 손실을 달성하지 못합니다. 매개 변수 조합을 최적화하고 스톱 로스 및 수익 취득 수준을 적절히 조정하는 것이 좋습니다.

최적화 방향

시장 변동성의 변화를 더 잘 파악하기 위해 실시간으로 ATR 매개 변수를 최적화하는 것을 고려하십시오. 또한 트렌드를 식별하기 위해 다른 지표를 연구하면 전략의 안정성을 더욱 향상시킬 수 있습니다. 스톱 로스 및 영리 관점에서 동적 트레일링은 또한 실현 가능한 최적화 방향입니다.

요약

슈퍼트렌드 잉글핑 전략은 트렌드 추적 및 패턴 인식의 장점을 통합하여 잉글링 패턴을 반전 신호로 사용합니다. 시장 전환점에 더 높은 수익을 얻을 수 있습니다. 그러나 전략에는 가짜 신호의 특정 위험이 있습니다. 위험을 제어하기 위해 추가 테스트와 최적화가 필요합니다.


/*backtest
start: 2023-11-07 00:00:00
end: 2023-12-07 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/
// © Armanhammer

//@version=5
strategy("Engulfing with Trend", overlay=true)

Periods = input.int(title="ATR Period", defval=10)
src = input(hl2, title="Source")
Multiplier = input.float(title="ATR Multiplier", step=0.1, defval=3.0)
changeATR= input.bool(title="Change ATR Calculation Method ?", defval=true)
showsignals = input.bool(title="Show Buy/Sell Signals ?", defval=true)
highlighting = input.bool(title="Highlighter On/Off ?", defval=true)

atr2 = ta.sma(src, Periods)
atr= changeATR ? ta.atr(Periods) : atr2

up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? math.max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? math.min(dn, dn1) : dn

var trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend

upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal and showsignals ? up : na, title="Buy", style=shape.labelup, location=location.absolute, color=color.new(color.green, 0), text="Buy")
//plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
//plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal and showsignals ? dn : na, title="Sell", style=shape.labeldown, location=location.absolute, color=color.new(color.red, 0), text="Sell")
//plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
//plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting and trend == 1 ? color.new(color.green, 0) : na
shortFillColor = highlighting and trend == -1 ? color.new(color.red, 0) : na
fill(upPlot, dnPlot, color=longFillColor)
fill(dnPlot, upPlot, color=shortFillColor)
alertcondition(buySignal, title="SuperTrend Buy", message="SuperTrend Buy!")
alertcondition(sellSignal, title="SuperTrend Sell", message="SuperTrend Sell!")
changeCond = trend != trend[1]
alertcondition(changeCond, title="SuperTrend Direction Change", message="SuperTrend has changed direction!")

// Define Downtrend and Uptrend conditions
downtrend = trend == -1
uptrend = trend == 1


// Engulfing
boringThreshold = input.float(25, title="Boring Candle Threshold (%)", minval=1, maxval=100)
engulfingThreshold = input.float(50, title="Engulfing Candle Threshold (%)", minval=1, maxval=100)
stopLevel = input.int(200, title="Stop Level (Pips)", minval=1)

// Boring Candle (Inside Bar) and Engulfing Candlestick Conditions
isBoringCandle = math.abs(open[1] - close[1]) * 100 / math.abs(high[1] - low[1]) <= boringThreshold
isEngulfingCandle = math.abs(open - close) * 100 / math.abs(high - low) <= engulfingThreshold

// Bullish and Bearish Engulfing Conditions
bullEngulfing = uptrend and close[1] < open[1] and close > open[1] and not isBoringCandle and not isEngulfingCandle
bearEngulfing = downtrend and close[1] > open[1] and close < open[1] and not isBoringCandle and not isEngulfingCandle

// Stop Loss, Take Profit, and Entry Price Calculation
bullStop = close + (stopLevel * syminfo.mintick)
bearStop = close - (stopLevel * syminfo.mintick)
bullSL = low 
bearSL = high
bullTP = bullStop + (bullStop - low)
bearTP = bearStop - (high - bearStop)

// Entry Conditions
enterLong = bullEngulfing and uptrend
enterShort = bearEngulfing and downtrend

// Exit Conditions
exitLong = ta.crossover(close, bullTP) or ta.crossover(close, bullSL)
exitShort = ta.crossover(close, bearTP) or ta.crossover(close, bearSL)

// Check if exit conditions are met by the next candle
exitLongNextCandle = exitLong and (ta.crossover(close[1], bullTP[1]) or ta.crossover(close[1], bullSL[1]))
exitShortNextCandle = exitShort and (ta.crossover(close[1], bearTP[1]) or ta.crossover(close[1], bearSL[1]))

// Strategy Execution
if enterLong
    strategy.entry("Buy", strategy.long)

if enterShort
    strategy.entry("Sell", strategy.short)

// Exit Conditions for Long (Buy) Positions
if bullEngulfing and not na(bullTP) and not na(bullSL)
    strategy.exit("Exit Long", from_entry="Buy", stop=bullSL, limit=bullTP)

// Exit Conditions for Short (Sell) Positions
if bearEngulfing and not na(bearTP) and not na(bearSL)
    strategy.exit("Exit Short", from_entry="Sell", stop=bearSL, limit=bearTP)


// Plot Shapes and Labels
plotshape(series=bullEngulfing, style=shape.triangleup, location=location.abovebar, color=color.green)
plotshape(series=bearEngulfing, style=shape.triangledown, location=location.abovebar, color=color.red)

// Determine OP, SL, and TP
plot(series=bullEngulfing ? bullStop : na, title="Bullish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(series=bearEngulfing ? bearStop : na, title="Bearish Engulfing stop", color=color.red, linewidth=3, style=plot.style_linebr)
plot(series=bullEngulfing ? bullSL : na, title="Bullish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(series=bearEngulfing ? bearSL : na, title="Bearish Engulfing SL", color=color.red, linewidth=3, style=plot.style_linebr)
plot(series=bullEngulfing ? bullTP : na, title="Bullish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)
plot(series=bearEngulfing ? bearTP : na, title="Bearish Engulfing TP", color=color.green, linewidth=3, style=plot.style_linebr)

// Create labels if the condition for bullEngulfing or bearEngulfing is met
//if bullEngulfing
   // label.new(x=bar_index, y=bullSL, text="SL: " + str.tostring(bullSL), color=color.red, textcolor=color.white, style=label.style_labelup, size=size.tiny)

//if bearEngulfing
   // label.new(x=bar_index, y=bearSL, text="SL: " + str.tostring(bearSL), color=color.red, textcolor=color.white, style=label.style_labeldown, size=size.tiny)

//if bullEngulfing
  //  label.new(x=bar_index, y=bullTP, text="TP: " + str.tostring(bullTP), color=color.green, textcolor=color.white, style=label.style_labeldown, size=size.tiny)

//if bearEngulfing
  //  label.new(x=bar_index, y=bearTP, text="TP: " + str.tostring(bearTP), color=color.green, textcolor=color.white, style=label.style_labelup, size=size.tiny)


더 많은