등급 반전 거래 전략은 평행선 시스템을 활용하여 매매 신호를 발산하는 트렌드 추적 전략이다. 그것은 다른 주기의 이동 평균을 계산하여 현재의 가격 트렌드 방향을 판단하고, 트렌드 반전 지점에서 구매 또는 판매 작업을 수행한다. 이 전략은 중장선 트렌드를 포착하여 트렌드 전환이 발생했을 때 거래를 한다.
이 전략은 두 개의 이동 평균을 계산하여 거래 신호를 생성합니다. 하나의 평균은 더 긴 기간을 기준으로하고 다른 평균은 더 짧은 기간을 기준으로합니다. 구체적인 작동 논리는 다음과 같습니다.
기준 평균선을 계산하고, 주기적 변수 len1로, 더 긴 주기적 경향을 나타내는 평균선을 계산한다.
신호 평균선을 계산하고, 주기 변수 len2로, 짧은 주기 경향을 나타내는 평균선을 계산하고, len2
짧은 평균선이 위쪽에서 아래쪽으로 내려가 긴 평균선을 통과했을 때, 폭매 거래는 트렌드가 반전되어 주가가 내려갈 수 있음을 나타냅니다.
짧은 평균선이 아래쪽에서 긴 평균선을 돌파할 때, 더 많은 거래를 하고, 트렌드가 반전되고, 주가가 상승할 수 있음을 나타냅니다.
가격이 다시 긴 평균선 근처로 돌아왔을 때, 평점 포지션은 현금화된다.
따라서, 이동 평균의 교차를 통해 중장선 트렌드의 전환점을 포착하여 트렌드 트레이딩을 수행합니다.
평균선 교차 시스템을 사용하여 중간주기의 트렌드 반전을 효과적으로 포착할 수 있다.
트레이딩 신호는 간단하고 명확하며 이해하기 쉽습니다.
다양한 품종과 거래자에 맞게 사용자 정의 가능한 주기 파라미터.
스톱 로즈 스톱을 설정하여 각 리스크를 제어할 수 있습니다.
주식 가격에 대해 예측할 필요 없이, 추세 방향만을 고려해야 합니다.
진동상태에서 평행선이 교차하는 경우가 많아서 가짜 신호가 많이 발생한다.
단기 가격 변동에서 수익을 얻을 수 없으며, 중장기 트렌드 거래에만 적합하다.
평균선 시스템은 가격 변화에 뒤쳐져 있고, 트렌드 전환을 적시에 포착할 수 없다.
거래 빈도가 높지 않아 수익이 적을 수 있습니다.
시장에 맞게 거래 빈도를 조정하기 위해 매개 변수를 적절하게 조정해야 합니다.
MACD, KD 등과 같은 다른 기술 지표와 함께 확인하고, 가짜 신호를 필터링한다.
트렌드 필터를 추가하여 트렌드가 명확한 경우에만 신호를 냅니다.
다중 시간 프레임 거래, 다른 주기 평선이 동시에 작용하여 더 많은 거래 기회를 제공합니다.
동적으로 최적화된 변수, 주기적인 변수가 시장의 변화에 따라 달라진다.
기계학습 모델에 접속하여 추세 전환을 판단하는 데 도움을 줍니다.
등급 역전 거래 전략은 전체적으로 간단한 실용적인 트렌드 추적 전략이다. 그것은 중기 트렌드 역점을 평평선 교차로 판단하여 더 긴 시간 주기 가격 트렌드를 포착한다. 이 전략은 구현하기 쉽고 거래 신호는 명확하지만, 또한 몇 가지 제한이 있다. 매개 변수 설정을 지속적으로 최적화하고, 다른 기술 지표와 기계 학습을 도입하는 등의 방법으로 이 전략의 효과를 향상시키고, 시장 기회를 더 잘 포착할 수 있다.
/*backtest
start: 2022-10-02 00:00:00
end: 2023-10-08 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=3
//Created by 100kiwi
strategy(title = "TrapTrading", overlay = true)
/////////////////////////////////////////////////////////////////////
// COMPONENT CODE START
//*******************************************************************
// Backtesting Period Selector | Component by pbergden
//*******************************************************************
testStartYear = input(2015, "Backtest Start Year")
testStartMonth = input(1, "Backtest Start Month")
testStartDay = input(1, "Backtest Start Day")
testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)
testStopYear = input(2018, "Backtest Stop Year")
testStopMonth = input(12, "Backtest Stop Month")
testStopDay = input(31, "Backtest Stop Day")
testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
// A switch to control background coloring of the test period
testPeriodBackground = input(title="Color Background?", type=bool, defval=true)
testPeriodBackgroundColor = testPeriodBackground and (time >= testPeriodStart) and (time <= testPeriodStop) ? #00FF00 : na
bgcolor(testPeriodBackgroundColor, transp=97)
testPeriod() => true
// COMPONENT CODE STOP
/////////////////////////////////////////////////////////////////////
// input
buySide = input(defval = true, title = "Trade Direction (ON: Buy Side OFF: Sell Side)", type = bool)
counterTrend = input(defval = true, title = "Trade Mode (ON: Counter Trend OFF: Trend Following)", type = bool)
len1 = input(defval = 14, title = "Period")
multiple = input(defval = 1.4, title = "Multiple")
m1 = close - close[len1]
controlPoint = counterTrend ? lowest(abs(m1), len1) == abs(m1) : highest(abs(m1), len1) == abs(m1)
baseLine = valuewhen(controlPoint, avg(close, close[len1]), 0)
// trap line
atr = atr(len1)
line1Up = baseLine + (atr * multiple)
line2Up = baseLine + (atr * 2 * multiple)
line3Up = baseLine + (atr * 3 * multiple)
line4Up = baseLine + (atr * 4 * multiple)
line5Up = baseLine + (atr * 5 * multiple)
line6Up = baseLine + (atr * 6 * multiple)
line7Up = baseLine + (atr * 7 * multiple)
line8Up = baseLine + (atr * 8 * multiple)
line9Up = baseLine + (atr * 9 * multiple)
line10Up = baseLine + (atr * 10 * multiple)
line1Down = baseLine - (atr * multiple)
line2Down = baseLine - (atr * 2 * multiple)
line3Down = baseLine - (atr * 3 * multiple)
line4Down = baseLine - (atr * 4 * multiple)
line5Down = baseLine - (atr * 5 * multiple)
line6Down = baseLine - (atr * 6 * multiple)
line7Down = baseLine - (atr * 7 * multiple)
line8Down = baseLine - (atr * 8 * multiple)
line9Down = baseLine - (atr * 9 * multiple)
line10Down = baseLine - (atr * 9 * multiple)
// draw
color = close >= baseLine ? teal : red
barcolor(controlPoint ? yellow : na, title = "Candle Color")
plot(baseLine, title = "Base Line", color = white, linewidth = 4, style = stepline, transp = 0)
plot(line1Up, title = "1Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line2Up, title = "2Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line3Up, title = "3Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line4Up, title = "4Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line5Up, title = "5Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line6Up, title = "6Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line7Up, title = "7Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line8Up, title = "8Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line9Up, title = "9Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line10Up, title = "10Up Line", color = green, linewidth = 1, style = stepline, transp = 0)
plot(line1Down, title = "1Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line2Down, title = "2Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line3Down, title = "2Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line4Down, title = "4Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line5Down, title = "5Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line6Down, title = "6Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line7Down, title = "7Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line8Down, title = "8Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line9Down, title = "9Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
plot(line10Down, title = "10Down Line", color = red, linewidth = 1, style = stepline, transp = 0)
// strategy code
if testPeriod() and buySide
strategy.exit("Exit Long0", from_entry = "Long0", qty = 1, limit = line2Up)
strategy.exit("Exit Long1", from_entry = "Long1", qty = 1, limit = line1Up)
strategy.exit("Exit Long2", from_entry = "Long2", qty = 1, limit = baseLine)
strategy.exit("Exit Long3", from_entry = "Long3", qty = 1, limit = line1Down)
strategy.exit("Exit Long4", from_entry = "Long4", qty = 1, limit = line2Down)
strategy.exit("Exit Long5", from_entry = "Long5", qty = 1, limit = line3Down)
strategy.exit("Exit Long6", from_entry = "Long6", qty = 1, limit = line4Down)
strategy.exit("Exit Long7", from_entry = "Long7", qty = 1, limit = line5Down)
strategy.exit("Exit Long8", from_entry = "Long8", qty = 1, limit = line6Down)
strategy.exit("Exit Long9", from_entry = "Long9", qty = 1, limit = line7Down)
strategy.exit("Exit Long10", from_entry = "Long10", qty = 1, limit = line8Down)
strategy.order("Long0", strategy.long, qty = 1, limit = baseLine, when = strategy.position_size <= 0)
strategy.order("Long1", strategy.long, qty = 1, limit = line1Down, when = strategy.position_size <= 1)
strategy.order("Long2", strategy.long, qty = 1, limit = line2Down, when = strategy.position_size <= 2)
strategy.order("Long3", strategy.long, qty = 1, limit = line3Down, when = strategy.position_size <= 3)
strategy.order("Long4", strategy.long, qty = 1, limit = line4Down, when = strategy.position_size <= 4)
strategy.order("Long5", strategy.long, qty = 1, limit = line5Down, when = strategy.position_size <= 5)
strategy.order("Long6", strategy.long, qty = 1, limit = line6Down, when = strategy.position_size <= 6)
strategy.order("Long7", strategy.long, qty = 1, limit = line7Down, when = strategy.position_size <= 7)
strategy.order("Long8", strategy.long, qty = 1, limit = line8Down, when = strategy.position_size <= 8)
strategy.order("Long9", strategy.long, qty = 1, limit = line9Down, when = strategy.position_size <= 9)
strategy.order("Long10", strategy.long, qty = 1, limit = line10Down, when = strategy.position_size <= 10)
else
if testPeriod() and not buySide
strategy.exit("Exit Short0", from_entry = "Short0", qty = 1, limit = line2Down)
strategy.exit("Exit Short1", from_entry = "Short1", qty = 1, limit = line1Down)
strategy.exit("Exit Short2", from_entry = "Short2", qty = 1, limit = baseLine)
strategy.exit("Exit Short3", from_entry = "Short3", qty = 1, limit = line1Up)
strategy.exit("Exit Short4", from_entry = "Short4", qty = 1, limit = line2Up)
strategy.exit("Exit Short5", from_entry = "Short5", qty = 1, limit = line3Up)
strategy.exit("Exit Short6", from_entry = "Short6", qty = 1, limit = line4Up)
strategy.exit("Exit Short7", from_entry = "Short7", qty = 1, limit = line5Up)
strategy.exit("Exit Short8", from_entry = "Short8", qty = 1, limit = line6Up)
strategy.exit("Exit Short9", from_entry = "Short9", qty = 1, limit = line7Up)
strategy.exit("Exit Short10", from_entry = "Short10", qty = 1, limit = line8Up)
strategy.order("Short0", strategy.short, qty = 1, limit = baseLine, when = strategy.position_size >= 0)
strategy.order("Short1", strategy.short, qty = 1, limit = line1Up, when = strategy.position_size >= -1)
strategy.order("Short2", strategy.short, qty = 1, limit = line2Up, when = strategy.position_size >= -2)
strategy.order("Short3", strategy.short, qty = 1, limit = line3Up, when = strategy.position_size >= -3)
strategy.order("Short4", strategy.short, qty = 1, limit = line4Up, when = strategy.position_size >= -4)
strategy.order("Short5", strategy.short, qty = 1, limit = line5Up, when = strategy.position_size >= -5)
strategy.order("Short6", strategy.short, qty = 1, limit = line6Up, when = strategy.position_size >= -6)
strategy.order("Short7", strategy.short, qty = 1, limit = line7Up, when = strategy.position_size >= -7)
strategy.order("Short8", strategy.short, qty = 1, limit = line8Up, when = strategy.position_size >= -8)
strategy.order("Short9", strategy.short, qty = 1, limit = line9Up, when = strategy.position_size >= -9)
strategy.order("Short10", strategy.short, qty = 1, limit = line10Up, when = strategy.position_size >= -10)