
이것은 두 개의 다른 시간 주기에서 지수 이동 평균을 교차하여 다공개하는 자동 거래 전략이다. 그것은 간단한 기술 지표를 사용하여 초보자 학습과 연습에 적합하다.
이 전략은 두 개의 지수 이동 평균을 사용한다. 하나는 큰 시간 주기 평균이고, 하나는 현재 주기 평균이다. 현재 주기 평균선 위에 큰 주기 평균선을 통과할 때, 더 많이 하고, 현재 주기 평균선 아래에 큰 주기 평균선을 통과할 때, 공백을 한다.
특히, 전략은 두 개의 평균선 변수를 먼저 정의합니다.
그리고 두 개의 EMA를 각각 계산합니다.
마지막으로, 거래 논리:
이렇게 하면, 다른 시간 주기 평균선의 교차를 통해 트렌드 방향을 판단하여 자동으로 거래할 수 있다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
스톱로스를 설정하거나, 변수 조합을 최적화하거나, 다른 지표를 추가하는 등의 방법으로 위험을 줄일 수 있다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
이 지수 이동 평균 교차 전략은 간단한 지수 캡처 트렌드를 적용하여 초보자 학습 연습에 적합합니다. 최적화 공간이 넓고, 더 많은 기술적 지표와 모델을 도입하여 더 강력한 효과의 정량 거래 전략을 개발할 수 있습니다.
/*backtest
start: 2023-09-16 00:00:00
end: 2023-10-16 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
strategy("Noro's Singapore Strategy", shorttitle = "Singapore str", overlay = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, pyramiding = 0)
//Settings
needlong = input(true, defval = true, title = "Long")
needshort = input(true, defval = true, title = "Short")
capital = input(100, defval = 100, minval = 1, maxval = 10000, title = "Lot")
tf = input("D", title = "Big Timeframe")
len = input(3, minval = 1, title = "MA length")
src = input(close, title = "MA Source")
fromyear = input(1900, defval = 1900, minval = 1900, maxval = 2100, title = "From Year")
toyear = input(2100, defval = 2100, minval = 1900, maxval = 2100, title = "To Year")
frommonth = input(01, defval = 01, minval = 01, maxval = 12, title = "From Month")
tomonth = input(12, defval = 12, minval = 01, maxval = 12, title = "To Month")
fromday = input(01, defval = 01, minval = 01, maxval = 31, title = "From day")
today = input(31, defval = 31, minval = 01, maxval = 31, title = "To day")
//MAs
ma1 = request.security(syminfo.tickerid, tf, sma(src, len))
ma2 = sma(src, len)
plot(ma1, linewidth = 2, color = blue, title = "Big TF MA")
plot(ma2, linewidth = 2, color = red, title = "MA")
//Trading
size = strategy.position_size
lot = 0.0
lot := size != size[1] ? strategy.equity / close * capital / 100 : lot[1]
if ma2 > ma1
strategy.entry("L", strategy.long, needlong ? lot : 0, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if ma2 < ma1
strategy.entry("S", strategy.short, needshort ? lot : 0, when = (time > timestamp(fromyear, frommonth, fromday, 00, 00) and time < timestamp(toyear, tomonth, today, 23, 59)))
if time > timestamp(toyear, tomonth, today, 23, 59)
strategy.close_all()