이 전략은 뉴럴 네트워크 모델, RSI 지표, 그리고 슈퍼 트렌드 지표를 결합하여 거래한다.
그 논리는 다음과 같습니다.
거래량 변화율, 브린밴드, RSI 등의 다차원 데이터를 입력하여 신경망 모델을 구축
인터넷은 미래의 가격 변화를 예측할 수 있습니다.
RSI 지표값을 계산하고 RSI와 예측된 가격 변화율을 조합합니다.
RSI 지표 값에 따라 동적 스톱 로드 라인을 생성합니다.
가격이 상향 스톱 라인을 넘으면 공백; 가격이 하향 스톱 라인을 넘으면 추가
슈퍼 트렌드 지표와 결합된 트렌드 판단을 필터링
이 전략은 복잡한 데이터에 대한 신경망의 시뮬레이션 능력을 최대한 활용하고 RSI와 슈퍼 트렌드와 같은 지표와 함께 신호 검증을 지원하여 판단의 정확성을 높이는 동시에 거래 위험을 제어합니다.
다차원 데이터 모델링에 대한 뉴런 네트워크 판단 경향
RSI 상쇄는 수익을 보호하고, 슈퍼 트렌드는 보조 판단
다중 지표 조합 검증, 신호 품질 향상
많은 양의 데이터가 필요한 신경망 훈련
RSI와 슈퍼 트렌드 파라미터가 최적화 조정
효과는 모델 판단에 의존하고, 불확실성이 있습니다.
이 전략은 기계학습 기술을 통해 전통적인 지표 판단을 보완하여 효율성을 추구하면서 위험을 통제한다. 그러나 그것의 매개 변수 조정 및 모델 해석성은 여전히 개선되어야 한다.
/*backtest
start: 2023-08-14 00:00:00
end: 2023-09-13 00:00:00
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
//ANN taken from https://www.tradingview.com/script/Eq4zZsTI-ANN-MACD-BTC/
//it only work for BTC as the ANN is trained for this data only
//super trend https://www.tradingview.com/script/VLWVV7tH-SuperTrend/
// Strategy version created for @che_trader
strategy ("ANN RSI SUPER TREND STRATEGY BY che_trader", overlay = true)
qty = input(10000, "Buy quantity")
testStartYear = input(2019, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testStartHour = input(0, "Backtest Start Hour")
testStartMin = input(0, "Backtest Start Minute")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,testStartHour,testStartMin)
testStopYear = input(2099, "Backtest Stop Year")
testStopMonth = input(1, "Backtest Stop Month")
testStopDay = input(30, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
testPeriod() => true
max_bars_back = (21)
src = close[0]
// Essential Functions
// Highest - Lowest Functions ( All efforts goes to RicardoSantos )
f_highest(_src, _length)=>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src[_i] >= _value ? _src[_i] : _value
_return = _value
f_lowest(_src, _length)=>
_adjusted_length = _length < 1 ? 1 : _length
_value = _src
for _i = 0 to (_adjusted_length-1)
_value := _src[_i] <= _value ? _src[_i] : _value
_return = _value
// Function Sum
f_sum(_src , _length) =>
_output = 0.00
_length_adjusted = _length < 1 ? 1 : _length
for i = 0 to _length_adjusted-1
_output := _output + _src[i]
// Unlocked Exponential Moving Average Function
f_ema(_src, _length)=>
_length_adjusted = _length < 1 ? 1 : _length
_multiplier = 2 / (_length_adjusted + 1)
_return = 0.00
_return := na(_return[1]) ? _src : ((_src - _return[1]) * _multiplier) + _return[1]
// Unlocked Moving Average Function
f_sma(_src, _length)=>
_output = 0.00
_length_adjusted = _length < 0 ? 0 : _length
w = cum(_src)
_output:= (w - w[_length_adjusted]) / _length_adjusted
_output
// Definition : Function Bollinger Bands
Multiplier = 2
_length_bb = 20
e_r = f_sma(src,_length_bb)
// Function Standard Deviation :
f_stdev(_src,_length) =>
float _output = na
_length_adjusted = _length < 2 ? 2 : _length
_avg = f_ema(_src , _length_adjusted)
evar = (_src - _avg) * (_src - _avg)
evar2 = ((f_sum(evar,_length_adjusted))/_length_adjusted)
_output := sqrt(evar2)
std_r = f_stdev(src , _length_bb )
upband = e_r + (Multiplier * std_r) // Upband
dnband = e_r - (Multiplier * std_r) // Lowband
basis = e_r // Midband
// Function : RSI
length = input(14, minval=1) //
f_rma(_src, _length) =>
_length_adjusted = _length < 1 ? 1 : _length
alpha = _length_adjusted
sum = 0.0
sum := (_src + (alpha - 1) * nz(sum[1])) / alpha
f_rsi(_src, _length) =>
_output = 0.00
_length_adjusted = _length < 0 ? 0 : _length
u = _length_adjusted < 1 ? max(_src - _src[_length_adjusted], 0) : max(_src - _src[1] , 0) // upward change
d = _length_adjusted < 1 ? max(_src[_length_adjusted] - _src, 0) : max(_src[1] - _src , 0) // downward change
rs = f_rma(u, _length) / f_rma(d, _length)
res = 100 - 100 / (1 + rs)
res
_rsi = f_rsi(src, length)
// MACD
_fastLength = input(12 , title = "MACD Fast Length")
_slowlength = input(26 , title = "MACD Slow Length")
_signalLength = input(9 , title = "MACD Signal Length")
_macd = f_ema(close, _fastLength) - f_ema(close, _slowlength)
_signal = f_ema(_macd, _signalLength)
_macdhist = _macd - _signal
// Inputs on Tangent Function :
tangentdiff(_src) => nz((_src - _src[1]) / _src[1] )
// Deep Learning Activation Function (Tanh) :
ActivationFunctionTanh(v) => (1 - exp(-2 * v))/( 1 + exp(-2 * v))
// DEEP LEARNING
// INPUTS :
input_1 = tangentdiff(volume)
input_2 = tangentdiff(dnband)
input_3 = tangentdiff(e_r)
input_4 = tangentdiff(upband)
input_5 = tangentdiff(_rsi)
input_6 = tangentdiff(_macdhist)
// LAYERS :
// Input Layers
n_0 = ActivationFunctionTanh(input_1 + 0)
n_1 = ActivationFunctionTanh(input_2 + 0)
n_2 = ActivationFunctionTanh(input_3 + 0)
n_3 = ActivationFunctionTanh(input_4 + 0)
n_4 = ActivationFunctionTanh(input_5 + 0)
n_5 = ActivationFunctionTanh(input_6 + 0)
// Hidden Layers
n_6 = ActivationFunctionTanh( -2.580743 * n_0 + -1.883627 * n_1 + -3.512462 * n_2 + -0.891063 * n_3 + -0.767728 * n_4 + -0.542699 * n_5 + 0.221093)
n_7 = ActivationFunctionTanh( -0.131977 * n_0 + -1.543499 * n_1 + 0.019450 * n_2 + 0.041301 * n_3 + -0.926690 * n_4 + -0.797512 * n_5 + -1.804061)
n_8 = ActivationFunctionTanh( -0.587905 * n_0 + -7.528007 * n_1 + -5.273207 * n_2 + 1.633836 * n_3 + 6.099666 * n_4 + 3.509443 * n_5 + -4.384254)
n_9 = ActivationFunctionTanh( -1.026331 * n_0 + -1.289491 * n_1 + -1.702887 * n_2 + -1.052681 * n_3 + -1.031452 * n_4 + -0.597999 * n_5 + -1.178839)
n_10 = ActivationFunctionTanh( -5.393730 * n_0 + -2.486204 * n_1 + 3.655614 * n_2 + 1.051512 * n_3 + -2.763198 * n_4 + 6.062295 * n_5 + -6.367982)
n_11 = ActivationFunctionTanh( 1.246882 * n_0 + -1.993206 * n_1 + 1.599518 * n_2 + 1.871801 * n_3 + 0.294797 * n_4 + -0.607512 * n_5 + -3.092821)
n_12 = ActivationFunctionTanh( -2.325161 * n_0 + -1.433500 * n_1 + -2.928094 * n_2 + -0.715416 * n_3 + -0.914663 * n_4 + -0.485397 * n_5 + -0.411227)
n_13 = ActivationFunctionTanh( -0.350585 * n_0 + -0.810108 * n_1 + -1.756149 * n_2 + -0.567176 * n_3 + -0.954021 * n_4 + -1.027830 * n_5 + -1.349766)
// Output Layer
_output = ActivationFunctionTanh(2.588784 * n_6 + 0.100819 * n_7 + -5.305373 * n_8 + 1.167093 * n_9 +
3.770143 * n_10 + 1.269190 * n_11 + 2.090862 * n_12 + 0.839791 * n_13 + -0.196165)
_chg_src = tangentdiff(src) * 100
_seed = (_output - _chg_src)
// BEGIN ACTUAL STRATEGY
length1 = input(title="RSI Period", type=input.integer, defval=21)
mult = input(title="RSI Multiplier", type=input.float, step=0.1, defval=4.0)
wicks = input(title="Take Wicks into Account ?", type=input.bool, defval=false)
showLabels = input(title="Show Buy/Sell Labels ?", type=input.bool, defval=true)
srsi = mult* rsi(_seed ,length1)
longStop = hl2 - srsi
longStopPrev = nz(longStop[1], longStop)
longStop := (wicks ? low[1] : close[1]) > longStopPrev ? max(longStop, longStopPrev) : longStop
shortStop = hl2 + srsi
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := (wicks ? high[1] : close[1]) < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and (wicks ? high : close) > shortStopPrev ? 1 : dir == 1 and (wicks ? low : close) < longStopPrev ? -1 : dir
longColor = color.green
shortColor = color.red
plot(dir == 1 ? longStop : na, title="Long Stop", style=plot.style_linebr, linewidth=2, color=longColor)
buySignal = dir == 1 and dir[1] == -1
plotshape(buySignal ? longStop : na, title="Long Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=longColor, transp=0)
plotshape(buySignal and showLabels ? longStop : na, title="Buy Label", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=longColor, textcolor=color.white, transp=0)
plot(dir == 1 ? na : shortStop, title="Short Stop", style=plot.style_linebr, linewidth=2, color=shortColor)
sellSignal = dir == -1 and dir[1] == 1
plotshape(sellSignal ? shortStop : na, title="Short Stop Start", location=location.absolute, style=shape.circle, size=size.tiny, color=shortColor, transp=0)
plotshape(sellSignal and showLabels ? shortStop : na, title="Sell Label", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=shortColor, textcolor=color.white, transp=0)
if testPeriod() and buySignal
strategy.entry("Long",strategy.long)
if testPeriod() and sellSignal
strategy.entry("Short",strategy.short)