
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))