
G-채널 트렌드 탐지 전략은 G 채널 지표에 기반한 정량 거래 전략이다. 이 전략은 G 채널의 상하 극한을 계산하고 G 채널의 평행선과 가격의 교차 상황에 따라 현재의 시장 동향을 판단하여 매매 신호를 생성한다. 이 전략은 또한 위험을 제어하기 위해 스톱 손실 조건을 설정한다.
G-채널 트렌드 탐지 전략은 G-채널 지표를 기반으로 한 간단한 양적 거래 전략으로, 시장 추세를 포착하여 매매 신호를 생성하고, 스톱 손실 조건을 설정하여 위험을 제어한다. 이 전략의 논리는 명확하고, 구현하기 쉬운, 양적 거래 초보자 학습에 적합하다. 그러나, 이 전략은 불안정한 시장에 대해 더 많은 가짜 신호를 생성할 수 있기 때문에, 스톱 손실 비율은 거래 품종의 특수성을 고려하지 않고 시장 특성에 따라 조정해야합니다.
//@version=5
// Full credit to AlexGrover: https://www.tradingview.com/script/fIvlS64B-G-Channels-Efficient-Calculation-Of-Upper-Lower-Extremities/
strategy("G-Channel Trend Detection Strategy", shorttitle="G-Trend", overlay=true)
// Input parameters
length = input.int(100, title="Length")
src = input(close, title="Source")
take_profit_percent = input.float(5.0, title="Take Profit (%)")
stop_loss_percent = input.float(2.0, title="Stop Loss (%)")
showcross = input.bool(true, title="Show Cross")
// Initialize variables
var float a = na
var float b = na
// Calculate a and b
a := math.max(src, nz(a[1])) - (nz(a[1]) - nz(b[1])) / length
b := math.min(src, nz(b[1])) + (nz(a[1]) - nz(b[1])) / length
// Calculate average
avg = (a + b) / 2
// Determine trend and color
crossup = ta.crossunder(b, close)
crossdn = ta.crossunder(a, close)
bullish = ta.barssince(crossdn) <= ta.barssince(crossup)
c = bullish ? color.lime : color.red
// Plotting
p1 = plot(avg, "Average", color=c, linewidth=1)
p2 = plot(close, "Close price", color=c, linewidth=1)
fill(p1, p2, c)
// Generate buy and sell signals
buy_signal = showcross and bullish and not bullish[1]
sell_signal = showcross and not bullish and bullish[1]
// Plot buy and sell signals on chart
plotshape(buy_signal ? avg : na, location=location.belowbar, style=shape.labeldown, color=color.new(color.lime, 0), size=size.tiny, text="Buy", textcolor=color.white, offset=-1)
plotshape(sell_signal ? avg : na, location=location.abovebar, style=shape.labelup, color=color.new(color.red, 0), size=size.tiny, text="Sell", textcolor=color.white, offset=-1)
// Alerts
alertcondition(buy_signal, title="Buy Signal", message="Buy Signal Detected")
alertcondition(sell_signal, title="Sell Signal", message="Sell Signal Detected")
// Calculate take profit and stop loss levels
take_profit_level = close * (1 + take_profit_percent / 100)
stop_loss_level = close * (1 - stop_loss_percent / 100)
// Strategy Entry and Exit
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_signal)
strategy.entry("Sell", strategy.short)
// Define the take profit and stop loss conditions for long positions
strategy.exit("Take Profit/Stop Loss", "Buy", limit=take_profit_level, stop=stop_loss_level)
// Define the take profit and stop loss conditions for short positions
strategy.exit("Take Profit/Stop Loss", "Sell", limit=close * (1 - take_profit_percent / 100), stop=close * (1 + stop_loss_percent / 100))