BlackBit 트레이더 XO 매크로 트렌드 스캐너 전략

저자:차오장, 날짜: 2024-01-25 15:21:46
태그:

img

전반적인 설명

이 전략은 트렌드 방향과 진입 지점을 식별하기 위해 이중 이동 평균과 StochRSI 지표를 결합합니다. 주요 특징은 트렌드의 초기 단계에서 시장에 진출 할 수 있으며 StochRSI의 과반 구매 / 과반 판매 특성을 사용하여 잘못된 브레이크를 필터링 할 수 있다는 것입니다.

전략 논리

이 전략은 이중 이동 평균 시스템을 구축하기 위해 빠른 이동 평균 EMA (12), 느린 이동 평균 EMA (25를 사용합니다. 빠른 선이 느린 선 위에 넘을 때 구매 신호가 생성됩니다. 빠른 선이 느린 선 아래에 넘을 때 판매 신호가 생성됩니다. 이것은 주요 트렌드 방향을 결정하는 데 사용됩니다.

동시에, 전략은 입시 시기를 추가로 식별하기 위해 StochRSI 크로스오버를 통합합니다. StochRSI는 스토카스틱 KDJ와 RSI를 결합합니다. K 라인이 과소매 구역에서 D 라인을 위로 넘을 때 구매 신호가 생성됩니다. K 라인이 과소매 구역에서 D 라인을 아래로 넘을 때 판매 신호가 생성됩니다.

이중 이동 평균이 신호를 생성하고 StochRSI가 대응 신호를 생성 할 때만이 전략은 포지션을 열 수 있습니다. 이것은 일부 잘못된 브레이크를 효과적으로 필터링하고 유효하지 않은 거래를 피할 수 있습니다.

이점 분석

이 전략의 가장 큰 장점은 트렌드 방향과 잠재적 진입 지점을 조기에 판단 할 수 있다는 것입니다. 이동 평균 시스템은 트렌드의 시작에 신호를 생성 할 수 있으며 StochRSI를 추가하면 잘못된 브레이크를 효과적으로 필터하고 잘못된 거래를 피할 수 있습니다.

또한, 전략은 트렌드 분석과 과잉 구매/ 과잉 판매 판단을 결합하여, 트렌드 추종과 평균 역전의 장점을 모두 갖추고 있습니다. 트렌드를 추적하거나 낮은 가격에 구매하고 높은 가격에 판매하든, 이 전략은 모든 측면에서 기회를 포착할 수 있습니다.

위험 분석

이 전략의 주요 위험은 이중 이동 평균 시스템 자체의 지연에 있습니다. 시장이 갑자기 격렬하게 변하면 이중 이동 평균 시스템은 종종 신호를 생성하는 데 시간이 걸리며 가장 좋은 입시 시기를 쉽게 놓칩니다.

또한 StochRSI는 잘못된 신호를 생성하여 불필요한 거래로 이어질 수 있습니다. 특히 K와 D 라인이 자주 교차 할 수있는 범위 시장에서 과도한 유효하지 않은 거래의 위험을 초래합니다.

최적화 방향

이 전략의 최적화는 주로 몇 가지 측면에 초점을 맞추고 있습니다.

  1. 트렌드를 파악하는 데 더 유리한 이동 평균 기간을 채택하기 위해 이중 이동 평균의 매개 변수를 조정합니다.

  2. StochRSI의 매개 변수를 최적화하여 더 합리적인 과반 구매/ 과반 판매 기준을 제시합니다.

  3. 주문 크기를 늘리거나 더 높은 수익을 추구하기 위해 스톱 로스/프로피를 조정합니다.

  4. 유효하지 않은 신호를 추가로 줄이기 위해 필터 조건으로 다른 지표를 포함합니다.

요약

전체적으로,이 전략은 중장기 트렌드를 포착하는 데 매우 적합하며, 트렌드의 초기 단계에서 큰 수익 잠재력을 가지고 있습니다. 보조 판사로서 StochRSI를 결합하면 잘못된 신호를 효과적으로 필터링하고 불필요한 손실을 피할 수 있습니다. 매개 변수 조정 및 리스크 관리의 개선으로,이 전략은 안정적인 수익을 얻는 강력한 도구가 될 수 있습니다.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-24 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/
// © btc_charlie / @TheParagonGrp

//@version=5
strategy('BlackBit Trader XO Macro Trend Scanner', overlay=true)

// Variables
var ok = 0
var countBuy = 0
var countSell = 0
src = input(close, title='OHLC Type')
i_fastEMA = input(12, title='Fast EMA')
i_slowEMA = input(25, title='Slow EMA')
i_defEMA = input(25, title='Consolidated EMA')

// Allow the option to show single or double EMA
i_bothEMAs = input(title='Show Both EMAs', defval=true)

// Define EMAs
v_fastEMA = ta.ema(src, i_fastEMA)
v_slowEMA = ta.ema(src, i_slowEMA)
v_biasEMA = ta.ema(src, i_defEMA)

// Color the EMAs
emaColor = v_fastEMA > v_slowEMA ? color.green : v_fastEMA < v_slowEMA ? color.red : #FF530D

// Plot EMAs
plot(i_bothEMAs ? na : v_biasEMA, color=emaColor, linewidth=3, title='Consolidated EMA')
plot(i_bothEMAs ? v_fastEMA : na, title='Fast EMA', color=emaColor)
plot(i_bothEMAs ? v_slowEMA : na, title='Slow EMA', color=emaColor)

// Colour the bars
buy = v_fastEMA > v_slowEMA
sell = v_fastEMA < v_slowEMA

if buy
    countBuy += 1
    countBuy

if buy
    countSell := 0
    countSell

if sell
    countSell += 1
    countSell

if sell
    countBuy := 0
    countBuy

buysignal = countBuy < 2 and countBuy > 0 and countSell < 1 and buy and not buy[1]
sellsignal = countSell > 0 and countSell < 2 and countBuy < 1 and sell and not sell[1]

barcolor(buysignal ? color.green : na)
barcolor(sellsignal ? color.red : na)


bull = countBuy > 1
bear = countSell > 1

barcolor(bull ? color.green : na)
barcolor(bear ? color.red : na)

// Set Alerts

// alertcondition(ta.crossover(v_fastEMA, v_slowEMA), title='Bullish EMA Cross', message='Bullish EMA crossover')
// alertcondition(ta.crossunder(v_fastEMA, v_slowEMA), title='Bearish EMA Cross', message='Bearish EMA Crossover')

// Stoch RSI code

smoothK = input.int(3, 'K', minval=1)
smoothD = input.int(3, 'D', minval=1)
lengthRSI = input.int(14, 'RSI Length', minval=1)
lengthStoch = input.int(14, 'Stochastic Length', minval=1)

rsi1 = ta.rsi(src, lengthRSI)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
d = ta.sma(k, smoothD)

bandno0 = input.int(80, minval=1, title='Upper Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno2 = input.int(50, minval=1, title='Middle Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')
bandno1 = input.int(20, minval=1, title='Lower Band', group='Bands (change this instead of length in Style for Stoch RSI colour to work properly)')

// Alerts

crossoverAlertBgColourMidOnOff = input.bool(title='Crossover Alert Background Colour (Middle Level) [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourOBOSOnOff = input.bool(title='Crossover Alert Background Colour (OB/OS Level) [ON/OFF]', group='Crossover Alerts', defval=false)

crossoverAlertBgColourGreaterThanOnOff = input.bool(title='Crossover Alert >input [ON/OFF]', group='Crossover Alerts', defval=false)
crossoverAlertBgColourLessThanOnOff = input.bool(title='Crossover Alert <input [ON/OFF]', group='Crossover Alerts', defval=false)

maTypeChoice = input.string('EMA', title='MA Type', group='Moving Average', options=['EMA', 'WMA', 'SMA', 'None'])
maSrc = input.source(close, title='MA Source', group='Moving Average')
maLen = input.int(200, minval=1, title='MA Length', group='Moving Average')

maValue = if maTypeChoice == 'EMA'
    ta.ema(maSrc, maLen)
else if maTypeChoice == 'WMA'
    ta.wma(maSrc, maLen)
else if maTypeChoice == 'SMA'
    ta.sma(maSrc, maLen)
else
    0

crossupCHECK = maTypeChoice == 'None' or open > maValue and maTypeChoice != 'None'
crossdownCHECK = maTypeChoice == 'None' or open < maValue and maTypeChoice != 'None'

crossupalert = crossupCHECK and ta.crossover(k, d) and (k < bandno2 or d < bandno2)
crossdownalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno2 or d > bandno2)
crossupOSalert = crossupCHECK and ta.crossover(k, d) and (k < bandno1 or d < bandno1)
crossdownOBalert = crossdownCHECK and ta.crossunder(k, d) and (k > bandno0 or d > bandno0)

aboveBandalert = ta.crossunder(k, bandno0)
belowBandalert = ta.crossover(k, bandno1)

bgcolor(color=crossupalert and crossoverAlertBgColourMidOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert Background Colour (Middle Level)', transp=70)
bgcolor(color=crossupOSalert and crossoverAlertBgColourOBOSOnOff ? #fbc02d : crossdownOBalert and crossoverAlertBgColourOBOSOnOff ? #000000 : na, title='Crossover Alert Background Colour (OB/OS Level)', transp=70)

bgcolor(color=aboveBandalert and crossoverAlertBgColourGreaterThanOnOff ? #ff0014 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K > Upper level', transp=70)
bgcolor(color=belowBandalert and crossoverAlertBgColourLessThanOnOff ? #4CAF50 : crossdownalert and crossoverAlertBgColourMidOnOff ? #FF0000 : na, title='Crossover Alert - K < Lower level', transp=70)

// alertcondition(crossupalert or crossdownalert, title='Stoch RSI Crossover', message='STOCH RSI CROSSOVER')

// Calculate start/end date and time condition
startDate = input(timestamp('2000-12-24T00:00:00'),group = "---------TIME RANGE SETTINGS---------")
finishDate = input(timestamp('2029-02-26T00:00:00'),group = "---------TIME RANGE SETTINGS---------")
time_cond = true


//ema filter
emalen = input(200,"EMA Filter Length",group = "EMA FILTER SETTINGS")
emasource = input(close,"EMA Filter Source",group = "EMA FILTER SETTINGS")
ema_fil = ta.ema(emasource,emalen)
plot(ema_fil,"EMA Filter")

//macd
fast_length = input(title="Fast Length", defval=26,group = "MACD FILTER SETTINGS")
slow_length = input(title="Slow Length", defval=100,group = "MACD FILTER SETTINGS")
src_macd = input(title="Source", defval=close,group = "MACD FILTER SETTINGS")
signal_length = input.int(title="Signal Smoothing",  minval = 1, maxval = 50, defval = 9,group = "MACD FILTER SETTINGS")
sma_source = input.string(title="Oscillator MA Type",  defval="EMA", options=["SMA", "EMA"],group = "MACD FILTER SETTINGS")
sma_signal = input.string(title="Signal Line MA Type", defval="EMA", options=["SMA", "EMA"],group = "MACD FILTER SETTINGS")

// Calculating
fast_ma = sma_source == "SMA" ? ta.sma(src_macd, fast_length) : ta.ema(src_macd, fast_length)
slow_ma = sma_source == "SMA" ? ta.sma(src_macd, slow_length) : ta.ema(src_macd, slow_length)
macd = fast_ma - slow_ma
signal = sma_signal == "SMA" ? ta.sma(macd, signal_length) : ta.ema(macd, signal_length)
hist = macd - signal

//tpsl
takeprofit=input.float(defval=0.3,title="Enter The Take Profit %",group="TP/SL CONDITION INPUTS HERE")/100
stoploss=input.float(defval=0.16,title="Enter The Stop %",group="TP/SL CONDITION INPUTS HERE")/100
tp = strategy.opentrades.entry_price(0)*takeprofit/syminfo.mintick
sl = strategy.opentrades.entry_price(0)*stoploss/syminfo.mintick

lg_rule = buysignal and hist > 0 and close > ema_fil
sh_rule = sellsignal and hist < 0 and close < ema_fil

// Plot Bull/Bear

plotshape(lg_rule, title='Bull', text='Bull', style=shape.triangleup, location=location.belowbar, color=color.new(color.green, 0), textcolor=color.new(color.black, 0), size=size.tiny)
plotshape(sh_rule, title='Bear', text='Bear', style=shape.triangledown, location=location.abovebar, color=color.new(color.red, 0), textcolor=color.new(color.black, 0), size=size.tiny)

//alert
lg_entryal = input("Long entry","Long entry alert",group = "ALERT MESSAGE SETTINGS")
sh_entryal = input("Short entry","Short entry alert",group = "ALERT MESSAGE SETTINGS")

if lg_rule and time_cond and barstate.isconfirmed
    strategy.entry("LONG",strategy.long)
    alert(lg_entryal,alert.freq_once_per_bar_close)
if strategy.position_size > 0
    strategy.exit("LONG EX","LONG",loss = sl,profit = tp,comment_loss = "LONG SL",comment_profit = "LONG TP")

if sh_rule and time_cond and barstate.isconfirmed
    strategy.entry("SHORT",strategy.short)
    alert(sh_entryal,alert.freq_once_per_bar_close)

if strategy.position_size < 0
    strategy.exit("SHORT EX","SHORT",loss = sl,profit = tp,comment_loss = "SHORT SL",comment_profit = "SHORT TP")

//end

더 많은