
이 전략은 이동 평균의 간단한 전략에 기반하며, 다른 통화 쌍에서 좋은 효과를 얻을 수 있습니다. 그것은 오픈 평균과 클로징 평균을 그리며, 두 가지 선이 교차 할 때 다중 포지션을 설정하거나 종료하기로 결정합니다. 그것의 원칙은 평균 클로징 가격이 상승할 때 포지션을 구축하는 것입니다. 이것은 미래의 가격이 상승할 것을 예고 할 수 있습니다. 평균 클로징 가격이 떨어질 때 포지션을 평행하는 것은 미래의 가격이 떨어질 것을 예고 할 수 있습니다.
이 전략은 우선 EMA, SMA, RMA, WMA, VWMA를 포함한 이동 평균의 유형을 설정합니다. 그리고 이동 평균 계산의 주기를 설정합니다. 일반적으로 10에서 250 K 선입니다. 다른 통화 쌍에 따라 다른 이동 평균 유형과 주기를 선택하면 완전히 다른 효과를 얻을 수 있습니다.
이 전략의 구체적인 거래 논리는 다음과 같습니다.
포지션을 설정할 때는 가격 상승의 징조로 간주하고, 포지션을 해소할 때는 가격 하락의 징조로 간주한다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
대응과 최적화 방향:
이 전략은 전체적으로 논리적으로 간단하며, 이동 평균 지표를 사용하여 가격 추세와 전환점을 판단한다. 그것은 파라미터를 조정하여 매우 좋은 효과를 얻을 수 있으며, 추가적으로 개선하고 적용할 가치가있는 효과적인 트렌드 추적 전략이다. 그러나 위험을 통제하고 적절한 통화 쌍과 파라미터를 선택하여 최대한의 효과를 발휘하는 데 주의를 기울여야 한다.
/*backtest
start: 2023-12-01 00:00:00
end: 2023-12-31 23:59:59
period: 2h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
//Author @divonn1994
initial_balance = 100
strategy(title='Close v Open Moving Averages Strategy', shorttitle = 'Close v Open', overlay=true, pyramiding=0, default_qty_value=100, default_qty_type=strategy.percent_of_equity, precision=7, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent, initial_capital=initial_balance)
//Input for number of bars for moving average, Switch to choose moving average type, Display Options and Time Frame of trading----------------------------------------------------------------
bars = input.int(66, "Moving average length (number of bars)", minval=1, group='Strategy') //66 bars and VWMA for BTCUSD on 12 Hours.. 35 bars and VWMA for BTCUSD on 1 Day
strategy = input.string("VWMA", "Moving Average type", options = ["EMA", "SMA", "RMA", "WMA", "VWMA"], group='Strategy')
redOn = input.string("On", "Red Background Color On/Off", options = ["On", "Off"], group='Display')
greenOn = input.string("On", "Green Background Color On/Off", options = ["On", "Off"], group='Display')
maOn = input.string("On", "Moving Average Plot On/Off", options = ["On", "Off"], group='Display')
startMonth = input.int(title='Start Month 1-12 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=12, group='Beginning of Strategy')
startDate = input.int(title='Start Date 1-31 (set any start time to 0 for furthest date)', defval=1, minval=0, maxval=31, group='Beginning of Strategy')
startYear = input.int(title='Start Year 2000-2100 (set any start time to 0 for furthest date)', defval=2011, minval=2000, maxval=2100, group='Beginning of Strategy')
endMonth = input.int(title='End Month 1-12 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=12, group='End of Strategy')
endDate = input.int(title='End Date 1-31 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=31, group='End of Strategy')
endYear = input.int(title='End Year 2000-2100 (set any end time to 0 for today\'s date)', defval=0, minval=0, maxval=2100, group='End of Strategy')
//Strategy Calculations-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
inDateRange = true
maMomentum = switch strategy
"EMA" => (ta.ema(close, bars) > ta.ema(open, bars)) ? 1 : -1
"SMA" => (ta.sma(close, bars) > ta.sma(open, bars)) ? 1 : -1
"RMA" => (ta.rma(close, bars) > ta.rma(open, bars)) ? 1 : -1
"WMA" => (ta.wma(close, bars) > ta.wma(open, bars)) ? 1 : -1
"VWMA" => (ta.vwma(close, bars) > ta.vwma(open, bars)) ? 1 : -1
=>
runtime.error("No matching MA type found.")
float(na)
openMA = switch strategy
"EMA" => ta.ema(open, bars)
"SMA" => ta.sma(open, bars)
"RMA" => ta.rma(open, bars)
"WMA" => ta.wma(open, bars)
"VWMA" => ta.vwma(open, bars)
=>
runtime.error("No matching MA type found.")
float(na)
closeMA = switch strategy
"EMA" => ta.ema(close, bars)
"SMA" => ta.sma(close, bars)
"RMA" => ta.rma(close, bars)
"WMA" => ta.wma(close, bars)
"VWMA" => ta.vwma(close, bars)
=>
runtime.error("No matching MA type found.")
float(na)
//Enter or Exit Positions--------------------------------------------------------------------------------------------------------------------------------------------------------------------
if ta.crossover(maMomentum, 0)
if inDateRange
strategy.entry('long', strategy.long, comment='long')
if ta.crossunder(maMomentum, 0)
if inDateRange
strategy.close('long')
//Plot Strategy Behavior---------------------------------------------------------------------------------------------------------------------------------------------------------------------
plot(series = maOn == "On" ? openMA : na, title = "Open moving Average", color = color.new(color.purple,0), linewidth=3, offset=1)
plot(series = maOn == "On" ? closeMA : na, title = "Close Moving Average", color = color.new(color.white,0), linewidth=2, offset=1)
bgcolor(color = inDateRange and (greenOn == "On") and maMomentum > 0 ? color.new(color.green,75) : inDateRange and (redOn == "On") and maMomentum <= 0 ? color.new(color.red,75) : na, offset=1)