부일시 삼키기 구매 및 판매 전략

저자:차오장, 날짜: 2023-12-27 14:25:11
태그:

img

전반적인 설명

불리쉬 잉글링 구매 및 판매 전략은 촛불 패턴에 기반한 양적 거래 전략이다. 불리쉬 잉글링?? 촛불 패턴을 식별함으로써 가격 반전으로부터 이익을 얻는 기회를 포착합니다. 이 전략의 주요 장점은 다음과 같습니다.

  1. 그것은 높은 확률의 가격 반전 기회를 식별하기 위해 성숙한 기술 분석 이론에 기반합니다.
  2. 간단하고 직관적인 거래 신호가 있습니다.
  3. 위험은 통제할 수 있습니다.

전략 논리

이 전략은 Bullish Engulfing 촛불 패턴을 기반으로 가격 반전을 식별합니다.

주가가 하락 추세에 있을 때, 작은 실제 몸집을 가진 촛불을 따라 실제 몸집이 이전 실제 몸집을 완전히 삼키고 닫는 가격이 이전 높은 가격보다 높으면, 이것은 불시 앙글링 패턴을 형성하고, 가격이 상승하기 시작하는 임박한 트렌드 반전을 신호합니다.

이 전략은 이윤을 확보하기 위해 1%의 수익 목표와 1%의 스톱 로스로, 올림 패턴이 확인되면 긴 포지션을 개척합니다.

이점 분석

이 전략의 장점은 다음과 같습니다.

  1. 성숙한 기술 분석 이론에 기초하고 있습니다.
  2. 거래 신호는 단순하고 직관적이며, 이해하기 쉽고 양적 거래에 자동화됩니다.
  3. 인덱스 선물과 같은 유동성 높은 상품 거래는 효율적인 입출입을 허용합니다.
  4. 이윤 목표와 스톱 로스 출구는 각 거래의 위험/이익 비율을 효과적으로 제어하여 수익성을 보장하고 큰 손실을 피합니다.
  5. 유연한 매개 변수 조정은 다양한 제품과 시장 환경에 적합합니다.

위험 분석

이 전략에는 몇 가지 위험이 있습니다.

  1. 잘못된 신호의 위험은 기술적 분석 이론에 근거하기 때문에 존재합니다.
  2. 시장 체제 변경은 조정이 필요한 매개 변수를 무효화 할 수 있습니다.
  3. 너무 좁은 스톱 로스 값은 조기 종료로 이어질 수 있고, 너무 넓은 값은 큰 손실을 초래할 수 있습니다.

이러한 위험을 해결하기 위해 우리는 다음과 같이 할 수 있습니다.

  1. 매개 변수를 최적화하고 시장 조건에서 성능을 확인합니다.
  2. 스톱 로스 레벨을 넓히고 단일 거래 손실을 수용 가능한 수준으로 제어합니다.
  3. 높은 유동성과 적절한 변동성을 가진 상품, 예를 들어 지수 및 선물 ETF를 거래합니다.

최적화 방향

이 전략은 또한 다음과 같이 강화될 수 있습니다.

  1. 트렌드에 맞지 않는 거래를 피하기 위해 이동 평균과 같은 필터를 추가합니다.
  2. 수익 잠재력을 확장하기 위해 수익 목표를 높이는 것입니다.
  3. 스톱 로스 메커니즘을 최적화합니다. 스톱 아웃의 확률을 줄이기 위해
  4. 다른 촛불 패턴의 조합을 사용하여 거래 시스템을 만듭니다.

결론

올리쉬 잉글핑 구매 및 판매 전략은 기술 분석에 기반한 성숙한 양적 거래 전략으로, 구현이 쉬운 간단하고 명확한 거래 신호의 장점이 있습니다. 최적화된 매개 변수와 좋은 위험 통제 조치로 안정적인 수익을 창출 할 수 있으며 매우 권장됩니다.


/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
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/
// © thequantscience

// ██████╗ ██╗   ██╗██╗     ██╗     ██╗███████╗██╗  ██╗    ███████╗███╗   ██╗ ██████╗ ██╗   ██╗██╗     ███████╗██╗███╗   ██╗ ██████╗ 
// ██╔══██╗██║   ██║██║     ██║     ██║██╔════╝██║  ██║    ██╔════╝████╗  ██║██╔════╝ ██║   ██║██║     ██╔════╝██║████╗  ██║██╔════╝ 
// ██████╔╝██║   ██║██║     ██║     ██║███████╗███████║    █████╗  ██╔██╗ ██║██║  ███╗██║   ██║██║     █████╗  ██║██╔██╗ ██║██║  ███╗
// ██╔══██╗██║   ██║██║     ██║     ██║╚════██║██╔══██║    ██╔══╝  ██║╚██╗██║██║   ██║██║   ██║██║     ██╔══╝  ██║██║╚██╗██║██║   ██║
// ██████╔╝╚██████╔╝███████╗███████╗██║███████║██║  ██║    ███████╗██║ ╚████║╚██████╔╝╚██████╔╝███████╗██║     ██║██║ ╚████║╚██████╔╝
// ╚═════╝  ╚═════╝ ╚══════╝╚══════╝╚═╝╚══════╝╚═╝  ╚═╝    ╚══════╝╚═╝  ╚═══╝ ╚═════╝  ╚═════╝ ╚══════╝╚═╝     ╚═╝╚═╝  ╚═══╝ ╚═════╝ 
                                                                                                                                  
//@version=5
strategy(
     "Buy&Sell Bullish Engulfing - The Quant Science",
     overlay = true,
     default_qty_type = strategy.percent_of_equity, 
     default_qty_value = 100,
     pyramiding = 1,
     currency = currency.EUR,
     initial_capital = 10000,
     commission_type = strategy.commission.percent,
     commission_value = 0.07,
     process_orders_on_close = true, 
     close_entries_rule = "ANY"
     )

startDate  = input.int(title="D: ", defval=1,    minval=1,    maxval=31,   inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")
startMonth = input.int(title="M: ", defval=1,    minval=1,    maxval=12,   inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")
startYear  = input.int(title="Y: ", defval=2022, minval=1800, maxval=2100, inline = 'Start', group = "START DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")

endDate    = input.int(title="D: ", defval=31,   minval=1,    maxval=31,   inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")
endMonth   = input.int(title="M: ", defval=12,   minval=1,    maxval=12,   inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")
endYear    = input.int(title="Y: ", defval=2023, minval=1800, maxval=2100, inline = 'End',   group = "END DATE BACKTESTING", tooltip = "D is Day, M is Month, Y is Year.")

inDateRange = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0)) and (time < timestamp(syminfo.timezone, endYear, endMonth, endDate, 0, 0))

PROFIT   = input.float(defval = 1, minval = 0, title = "Target profit (%): ", step = 0.10, group = "TAKE PROFIT-STOP LOSS")
STOPLOSS = input.float(defval = 1, minval = 0, title = "Stop Loss (%): ",     step = 0.10, group = "TAKE PROFIT-STOP LOSS")

var float equity_trades = 0
strategy.initial_capital = 50000
equity_trades := strategy.initial_capital
var float equity   = 0
var float qty_order   = 0
t_ordersize = "Percentage size of each new order. With 'Reinvestment Profit' activate, the size will be calculate on the equity, with 'Reinvestment Profit' deactivate the size will be calculate on the initial capital."
orders_size = input.float(defval = 2, title = "Orders size (%): ", minval = 0.10, step = 0.10,  maxval = 100, group = "RISK MANAGEMENT", tooltip = t_ordersize)
qty_order := ((equity_trades * orders_size) / 100 ) / close 

C_DownTrend = true
C_UpTrend   = true
var trendRule1 = "SMA50"
var trendRule2 = "SMA50, SMA200"
var trendRule = input.string(trendRule1, "Detect Trend Based On", options=[trendRule1, trendRule2, "No detection"], group = "BULLISH ENGULFING")

if trendRule == trendRule1
	priceAvg = ta.sma(close, 50)
	C_DownTrend := close < priceAvg
	C_UpTrend := close > priceAvg

if trendRule == trendRule2
	sma200 = ta.sma(close, 200)
	sma50  = ta.sma(close, 50)
	C_DownTrend := close < sma50 and sma50 < sma200
	C_UpTrend := close > sma50 and sma50 > sma200
C_Len = 14
C_ShadowPercent = 5.0 
C_ShadowEqualsPercent = 100.0
C_DojiBodyPercent = 5.0
C_Factor = 2.0 

C_BodyHi = math.max(close, open)
C_BodyLo = math.min(close, open)
C_Body = C_BodyHi - C_BodyLo
C_BodyAvg = ta.ema(C_Body, C_Len)
C_SmallBody = C_Body < C_BodyAvg
C_LongBody = C_Body > C_BodyAvg
C_UpShadow = high - C_BodyHi
C_DnShadow = C_BodyLo - low
C_HasUpShadow = C_UpShadow > C_ShadowPercent / 100 * C_Body
C_HasDnShadow = C_DnShadow > C_ShadowPercent / 100 * C_Body
C_WhiteBody = open < close
C_BlackBody = open > close
C_Range = high-low
C_IsInsideBar = C_BodyHi[1] > C_BodyHi and C_BodyLo[1] < C_BodyLo
C_BodyMiddle = C_Body / 2 + C_BodyLo
C_ShadowEquals = C_UpShadow == C_DnShadow or (math.abs(C_UpShadow - C_DnShadow) / C_DnShadow * 100) < C_ShadowEqualsPercent and (math.abs(C_DnShadow - C_UpShadow) / C_UpShadow * 100) < C_ShadowEqualsPercent
C_IsDojiBody = C_Range > 0 and C_Body <= C_Range * C_DojiBodyPercent / 100
C_Doji = C_IsDojiBody and C_ShadowEquals

patternLabelPosLow  = low  - (ta.atr(30) * 0.6)
patternLabelPosHigh = high + (ta.atr(30) * 0.6)

label_color_bullish = input.color(color.rgb(43, 255, 0), title = "Label Color Bullish", group = "BULLISH ENGULFING")
C_EngulfingBullishNumberOfCandles = 2
C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] )
if C_EngulfingBullish
    var ttBullishEngulfing = "Engulfing\nAt the end of a given downward trend, there will most likely be a reversal pattern. To distinguish the first day, this candlestick pattern uses a small body, followed by a day where the candle body fully overtakes the body from the day before, and closes in the trend’s opposite direction. Although similar to the outside reversal chart pattern, it is not essential for this pattern to completely overtake the range (high to low), rather only the open and the close."
    label.new(bar_index, patternLabelPosLow, text="BE", style=label.style_label_up, color = label_color_bullish, textcolor=color.white, tooltip = ttBullishEngulfing)
bgcolor(ta.highest(C_EngulfingBullish?1:0, C_EngulfingBullishNumberOfCandles)!=0 ? color.new(#21f321, 90) : na, offset=-(C_EngulfingBullishNumberOfCandles-1))

var float c       = 0
var float o       = 0
var float c_exit  = 0
var float c_stopl = 0

if C_EngulfingBullish and strategy.opentrades==0 and inDateRange 
    c := strategy.equity
    o := close
    c_exit  := c + (c * PROFIT / 100)
    c_stopl := c - (c * STOPLOSS / 100)
    strategy.entry(id = "LONG", direction = strategy.long, qty = qty_order, limit = o)

if ta.crossover(strategy.equity, c_exit)
    strategy.exit(id = "CLOSE-LONG", from_entry = "LONG", limit = close)
if ta.crossunder(strategy.equity, c_stopl)
    strategy.exit(id = "CLOSE-LONG", from_entry = "LONG", limit = close)


더 많은