이중 기하급수적 이동 평균 크로스오버 알고리즘 거래 전략

저자:차오장, 날짜: 2024-01-25 14:04:23
태그:

img

전반적인 설명

전략 논리

이점 분석

  1. 이 전략은 이중 EMA 크로스오버와 포터스 지표를 통합하여 이 둘을 모두 활용하여 신호 정확성을 향상시킵니다.

  2. 자금 관리 모듈은 각 거래에 대한 자본 할당을 제어하여 전반적인 위험을 관리합니다.

위험 분석

  1. EMA 크로스오버는 잘못된 신호를 생성할 수 있습니다. 그리고 스 지표도 잘못된 신호를 완전히 필터링할 수 없습니다. 여전히 몇 가지 손실 거래가 있을 수 있습니다.

  2. 이 전략은 스톱 로스에 의존하여 드라우다운을 제어합니다. 만약 스톱 아웃이 되면 손실은 예상보다 커질 수 있습니다.

개선 가능성:

  1. 신호 품질을 향상시키기 위해 EMA 매개 변수를 더 이상 최적화 할 수 있습니다.

  2. 더 나은 필터 신호에 더 많은 지표가 추가 될 수 있습니다.

  3. 기계 학습 알고리즘은 매개 변수를 자동으로 최적화하는 데 도움이 될 수 있습니다.

결론


/*backtest
start: 2023-01-18 00:00:00
end: 2024-01-24 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/
// © smottybugger 

//@version= 5
strategy("The  Averages Moving_X_Vortex", shorttitle="2.5billion BTC lol" , calc_on_order_fills=true, calc_on_every_tick=true, commission_type=strategy.commission.percent, commission_value=0.02, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, margin_long=0, margin_short=0,overlay=true)
// Dual Vortex
period_1 = input(15, "short Time")
period_2 = input(25, "long time")
VMP = math.sum(math.abs(high - low[3]), period_1)
VMM = math.sum(math.abs(low - high[1]), period_2)
STR = math.sum(ta.atr(1), period_1)
STR2 = math.sum(ta.atr(1), period_2)
VXpower= (input(5,"Vortex Power")/10000)*close
shorterV =(VMP / STR)*VXpower
longerV = (VMM / STR2)*VXpower

// MACross
shortlen = input(20, "ShortMa")
longlen = input(29, "LongMA")
shorterMA = ta.sma(close, shortlen)
longerMA = ta.sma(close, longlen)

// Vortex "MACross Stabilized"
Varance = input(1, "Vortex Stabilize")
Vpercent = (Varance / 100)
shortV= ((((shorterMA-close)* Vpercent)+shorterV)/2)+close
longV = ((((longerMA -close )*Vpercent)+longerV)/2)+close

//MAcross vortex stabilized
Marance = input(1, "MACross Stabilize")
MApercent = Marance / 100
shortMA = ((((shorterMA-close)*MApercent)+shorterV)/2)+close
longMA = ((((longerMA-close)*MApercent)+longerV)/2)+close

//VMXadveraged Moving cross adveraged
VMXL=(longV+longMA)/2
VMXS=(shortV+shortMA)/2
VXcross= ta.cross(VMXS,VMXL) ? VMXS : na
VMXcross= ta.cross(VMXS,VMXL)

//plot
plot(VMXS,"BUY",color=#42D420)
plot(VMXL,"SELL",color=#e20420)
crossV= ta.cross(shortV, longV) ? shortV : na
plot(shortV ,"shortV", color=#42D420)
plot(longV,"longV", color=#e20420)
plot(crossV,"crossV", color=#2962FF, style=plot.style_cross, linewidth=4)
crossMA = ta.cross(shortMA, longMA) ? shortMA : na
plot(shortMA,"shortMA", color=#42D420)
plot(longMA,"longMA", color=#e20420)
plot(crossMA,"crossMA", color=#2962FF, style=plot.style_cross, linewidth=4)
plot(VXcross,"VMXcross",color=#2962FF, style= plot.style_cross,linewidth=4)
plot(close,color=#999999)

// Vortex Condistyle
is_Vlong =shortV< longV
is_Vshort =shortV>longV


// Vortex commands
Vlong =  ta.crossunder(longV, shortV)
Vshort =ta.crossover(shortV,longV)
VorteX = ta.cross(longV, shortV)

// MACross Conditions
is_MAlong = shortMA < longV
is_MAshort = shortMA > shortV


//VMX Conditions
is_VMXlong=VMXS<VMXL
is_VMXshort=VMXS>VMXL

// MA commands
MAlong = ta.crossunder(shortMA, longV)
MAshort =ta.crossover(shortMA, shortV)
MAcross =  ta.cross(shortMA, longMA)
 
//VMX COMMANss
VMXBUY=ta.crossover( VMXS,VMXL)
VMXSELL=ta.crossunder(VMXS,VMXL)

// Close Crossing PositionLMXs

CS=is_MAshort or is_VMXshort
CL= is_MAlong or is_VMXlong
OS=MAshort or VMXSELL
OL=MAlong or VMXBUY


if VMXcross
    strategy.close_all ("closed")

//if CS and  OL
    strategy.close("Short",comment="Short Closed")


//if CL and  OS
    strategy.close("Long",comment="Long Closed" ) 

//CA1= is_MAcross and is_VorteX
//if CA1
   // strategy.close_all(comment="X2X")

// Defalongyntry qty

if is_VMXlong and VMXSELL
    strategy.entry("sell",strategy.short)


if is_VMXshort and VMXBUY
    strategy.entry("buy",strategy.long)



// Stop Losses & Taking Profit
sllp = input(0, "Stop Loss Long")
sll = (1 - sllp / 100) * strategy.position_avg_price
is_sll = input(true, "Stop Long")

tplp = input(0, "Take Profit Long")
tpl = (1 + tplp / 100) * strategy.position_avg_price
is_tpl = input(true, "Take Long")

slsp = input(0, "Stop Loss Short")
sls = (1 + slsp / 100) * strategy.position_avg_price
is_sls = input(true, "Stop Short")

tpsp = input(0, "Take Profit Short")
tps = (1 - tpsp / 100) * strategy.position_avg_price
is_tps = input(true, "Take Short")

if (is_sll or is_sls) 
    strategy.close("Stop Losses", qty_percent=100)

if (is_tpl or is_tps) 
    strategy.close("Take Profits", qty_percent=100)


 //Strategy Backtest
//plot(strategy.equity, "Equity", color=color.red, linewidth=2, style=plot.style_areabr)


더 많은