
이 전략은 MACD 지표의 쌍평선 교차를 계산하여 구매와 판매의 시간을 판단한다. 그것은 거래 신호를 제안하기 위해 차트에 화살 모양을 그리는 것이다.
이 전략은 먼저 패스트 라인 (EMA 12호기), 패스트 라인 (EMA 26호기) 및 MACD의 차이를 계산한다. 그리고는 패스트 라인과 패스트 라인의 골드 포크와 MACD의 차이의 양과 음을 기준으로 구매와 판매의 시간을 판단한다:
가짜 신호를 필터링하기 위해, 코드는 이전 K선의 신호 상태를 판단한다. 현재 K선 중 하나가 역전 신호 (구매가 판매로 전환되거나 판매가 구매로 전환) 인 경우에만 현재 신호가 트리거된다.
또한, K 온라인에서 구매 및 판매 시점을 알려주는 화살표가 코드에 그려져 있습니다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
이 전략은 다음과 같은 방향으로 최적화될 수 있습니다.
이 쌍평선 교차 화살 전략은 전체적으로 비교적 간단하고 실용적이며, 쌍평선 교차 판단과 MACD 차차 필터링을 통해 중장선 트렌드의 매매점을 식별할 수 있으며, 놓친 가격 전환을 피할 수 있다. 화살提示도 동작을 더 명확하게 명확하게 한다. 후기에는 변수 최적화, 필터링 조건을 증가시키는 등의 방법으로 전략의 안정성과 수익률을 더욱 강화할 수 있다.
/*backtest
start: 2022-11-14 00:00:00
end: 2023-11-20 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//Daniels stolen code
strategy(shorttitle="Daniels Stolen Code", title="Daniels Stolen Code", overlay=true, calc_on_order_fills=true, pyramiding=0)
//Define MACD Variables
fast = 12, slow = 26
fastMACD = ema(hlc3, fast)
slowMACD = ema(hlc3, slow)
macd = fastMACD - slowMACD
signal = sma(macd, 9)
hist = macd - signal
currMacd = hist[0]
prevMacd = hist[1]
currPrice = hl2[0]
prevPrice = hl2[1]
buy = currPrice > prevPrice and currMacd > prevMacd
sell = currPrice < prevPrice and currMacd < prevMacd
neutral = (currPrice < prevPrice and currMacd > prevMacd) or (currPrice > prevPrice and currMacd < prevMacd)
//Plot Arrows
timetobuy = buy==1 and (sell[1]==1 or (neutral[1]==1 and sell[2]==1) or (neutral[1]==1 and neutral[2]==1 and sell[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and sell[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and sell[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and sell[6]==1))
timetosell = sell==1 and (buy[1]==1 or (neutral[1]==1 and buy[2]==1) or (neutral[1]==1 and neutral[2]==1 and buy[3]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and buy[4]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and buy[5]==1) or (neutral[1]==1 and neutral[2]==1 and neutral[3]==1 and neutral[4]==1 and neutral[5]==1 and buy[6]==1))
plotshape(timetobuy, color=blue, location=location.belowbar, style=shape.arrowup)
plotshape(timetosell, color=red, location=location.abovebar, style=shape.arrowdown)
//plotshape(neutral, color=black, location=location.belowbar, style=shape.circle)
//Test Strategy
// strategy.entry("long", true, 1, when = timetobuy and time > timestamp(2017, 01, 01, 01, 01)) // buy by market if current open great then previous high
// strategy.close("long", when = timetosell and time > timestamp(2017, 01, 01, 01, 01))
strategy.order("buy", true, 1, when=timetobuy==1 and time > timestamp(2019, 01, 01, 01, 01))
strategy.order("sell", false, 1, when=timetosell==1 and time > timestamp(2019, 01, 01, 01, 01))
// strategy.entry(id = "Short", long = false, when = enterShort())
// strategy.close(id = "Short", when = exitShort())
//strategy.entry("long", true, 1, when = open > high[1]) // enter long by market if current open great then previous high
// strategy.exit("exit", "long", profit = 10, loss = 5) // ge