이것은 두 개의 이동평균선을 기반으로 한 거래 전략이다. 그것은 빠른 이동평균선과 느린 이동평균선의 교차 관계에 따라 시장의 추세를 판단하고 거래 신호를 생성한다. 빠른 평균선 상에서 느린 평균선을 통과하면 구매 신호를 생성하고 빠른 평균선 아래에서 느린 평균선을 통과하면 판매 신호를 생성한다.
이 전략은 주로 이동 평균선의 트렌드 추적 기능을 이용한다. 이동 평균선은 일정 주기 내의 역사적인 종결 가격에 따라 계산된 평균값이다. 그것은 하루 내의 작은 변동이 흐르며, 더 큰 시간 주기 내의 가격 트렌드를 반영한다. 빠른 평균선은 짧은 주기 사용, 가격 변화에 더 빨리 반응한다. 느린 평균선은 긴 주기 사용, 장기 트렌드를 나타낸다. 빠른 평균선 상의 느린 평균선은 단기 동향이 상향으로 돌파하여 장기 트렌드를 나타냅니다.
이 전략은 다른 주기 길이의 이동 평균선을 설정하여 평균선 사이의 교차를 사용하여 거래 신호를 형성한다. 단기 평균선 상에서 긴 주기 평균선을 통과하면 단기 시장이 좋아서 구매 신호를 생성한다. 단기 평균선 아래에서 긴 주기 평균선을 통과하면 단기 시장이 약해져서 판매 신호를 생성한다. 전략 코드는 plot 함수를 통해 평균선을 그리며, 트렌드 변수는 평균선의 교차 관계를 판단하고, 교차가 발생하면 구매 및 판매 신호를 출력한다.
쌍평선 교차 전략은 이동평선의 트렌드 추적 기능을 활용하여 빠른 속도로 평균선을 교차하여 거래 방향을 판단하고 거래 신호를 생성한다. 이 전략은 간단하고 쉽게 작동하지만 몇 가지 문제가 있습니다. 파라미터를 조정하고 다른 지표와 함께 작동하는 방법과 알고리즘 최적화를 통해 부족한 부분을 보완하여 안정적이고 신뢰할 수있는 거래 시스템으로 만들 수 있습니다.
/*backtest
start: 2023-01-01 00:00:00
end: 2023-04-14 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/
// © KivancOzbilgic
//@version=4
strategy("pomila", overlay=true)
Periods = input(title="ATR Period", type=input.integer, defval=10)
src = input(hl2, title="Source")
Multiplier = input(title="ATR Multiplier", type=input.float, step=0.1, defval=3.0)
changeATR= input(title="Change ATR Calculation Method ?", type=input.bool, defval=true)
showsignals = input(title="Show Buy/Sell Signals ?", type=input.bool, defval=false)
highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)
barcoloring = input(title="Bar Coloring On/Off ?", type=input.bool, defval=true)
atr2 = sma(tr, Periods)
atr= changeATR ? atr(Periods) : atr2
up=src-(Multiplier*atr)
up1 = nz(up[1],up)
up := close[1] > up1 ? max(up,up1) : up
dn=src+(Multiplier*atr)
dn1 = nz(dn[1], dn)
dn := close[1] < dn1 ? min(dn, dn1) : dn
trend = 1
trend := nz(trend[1], trend)
trend := trend == -1 and close > dn1 ? 1 : trend == 1 and close < up1 ? -1 : trend
upPlot = plot(trend == 1 ? up : na, title="Up Trend", style=plot.style_linebr, linewidth=2, color=color.green)
buySignal = trend == 1 and trend[1] == -1
plotshape(buySignal ? up : na, title="UpTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.green, transp=0)
plotshape(buySignal and showsignals ? up : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)
dnPlot = plot(trend == 1 ? na : dn, title="Down Trend", style=plot.style_linebr, linewidth=2, color=color.red)
sellSignal = trend == -1 and trend[1] == 1
plotshape(sellSignal ? dn : na, title="DownTrend Begins", location=location.absolute, style=shape.circle, size=size.tiny, color=color.red, transp=0)
plotshape(sellSignal and showsignals ? dn : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)
mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0)
longFillColor = highlighting ? (trend == 1 ? color.green : color.white) : color.white
shortFillColor = highlighting ? (trend == -1 ? color.red : color.white) : color.white
fill(mPlot, upPlot, title="UpTrend Highligter", color=longFillColor)
fill(mPlot, dnPlot, title="DownTrend Highligter", color=shortFillColor)
FromMonth = input(defval = 9, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2018, title = "From Year", minval = 999)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 999)
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() => time >= start and time <= finish ? true : false
longCondition = buySignal
if (longCondition)
strategy.entry("BUY", strategy.long, when = window())
shortCondition = sellSignal
if (shortCondition)
strategy.entry("SELL", strategy.short, when = window())
buy1= barssince(buySignal)
sell1 = barssince(sellSignal)
color1 = buy1[1] < sell1[1] ? color.green : buy1[1] > sell1[1] ? color.red : na
barcolor(barcoloring ? color1 : na)