
トレンドトラッキングストップ戦略は,トレンド指数TrendAlertに基づくストップトラッキング取引戦略である. トレンドAlert指数によってトレンドの方向性を判断し,トレンドトラッキング入場を実現する. 同時に,ATR指数を使用してストップロスを設定し,リスク管理を実現する.
この戦略は以下の部分から構成されています.
トレンドアラート指数は,トレンドの方向を判断する. トレンドアラートが0より大きい時は看板信号,0より小さい時は下落信号である.
ATR指数は,近期価格変動の範囲を計算する.ATRはATRのストップ・プローパーをatrStopMultiplierで固定したストップ・ポイントとして掛けます.
最低価格lowestLowと最高価格highestHighを組み合わせてATRストップはストップ追跡を構築する.structureパラメータの制御が有効であるかどうか.
トレンドシグナル方向に応じて,多引または短引のポジションに入ります. 入場後,テイクプロフィットとストップロスを設定します.
価格がストップ・ロースまたはストップ・ストップを触発した後の平仓.
この戦略は,トレンドを判断し,偽信号をフィルターし,ストップ・ローズ・コントロール・リスクを追跡し,収益性を確保し,取引システムの安定性を全般的に向上させるというものです.
この戦略の利点は以下の通りです.
トレンドフィルタリングとストップ・ロスの追跡は,市場騒音を追いかけるのを避けるための二重保証であり,取引リスクを制御できるようにします.
ATRは,多種多様な市場環境に適用される過度最適化防止のための自主的な止損設定である.
目標のストップは,利益を確保し,利益を食い尽くさないようにすることです.
戦略の論理は明快で簡潔で,修正は容易に理解でき,量化トレーダーの二次開発に適しています.
Pineスクリプト言語で書かれ,TradingViewプラットフォームで直接使用できます.プログラミングの基礎は不要です.
この戦略にはいくつかのリスクがあります.
トレンド判断の誤りにより,不必要な入場とストップがトリガーされる可能性がある.適切なストップ・ロスを緩め,入場信号をフィルターすることができる.
状況が激しく波動すると,ATRは実際の波幅を過小評価する可能性がある.この場合,ATRのストップ損失倍数atrStopMultiplierを増加させることができる.
ターゲットストップは,戦略の利益の余地を制限する可能性がある.市場によるlimitMultiplierパラメータの調整が可能である.
コード・エクスティストの論理は価格のみに基づいているが,実際には時間管理と組み合わせるべきである.
この戦略は以下の点で最適化できます.
パラメータを最適化してATR長さatrLengthと止損倍数atrStopMultiplierを設定し,止損アルゴリズムの感度を調整する.
異なるトレンドの指標を試し,よりよい入学タイミングを探してください.
特定の取引品種の特徴に応じてターゲットストップパラメータを選択または調整する.
時間の損失を防ぐ仕組みを導入し,一人泊りのリスクを回避する.
取引量指標のフィルターで偽の突破を組み合わせた戦略の安定性を向上させる.
この戦略は全体的に非常に実用的なトレンド追跡ストップ・ストップ戦略である.指標を用い,トレンドの方向性を判断し,トレンド追跡を実現し,同時に自己適応ストップを設定し,リスクコントロールを確保する.この戦略は論理的に明確で,使いやすい.初心者の学習に最適である.また,高度な戦略開発に優れた取引戦略の枠組みを提供している.量化トレーダーが深入に研究し,最適化する価値がある.
/*backtest
start: 2023-01-29 00:00:00
end: 2024-02-04 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jaque_verdatre
//@version=5
strategy("TrendAlert Based", overlay = true)
// Get inputs
TrendAlert = input.source(close, "TrendAlert")
atrLength = input.int(title="ATR Length", defval=15, minval=1)
useStructure = input.bool(title="Use Structure?", defval=true)
lookback = input.int(title="How Far To Look Back For High/Lows", defval=8, minval=1)
atrStopMultiplier = input.float(title="ATR Multiplier", defval=0.2, minval=0.1)
LimitMultiplier = input.float(title = "Limit Multiplier", defval = 0.5, minval = 0.1)
PineConnectorID = input.int(title = "Pine Connector ID",defval = 0)
CurrencyToSend = input.string(title = "personilized currency", defval = "ETHUSD")
Risk = input.int(title = "risk in % to send", defval = 10, minval = 1)
// Calculate data
atr = ta.atr(atrLength)
lowestLow = ta.lowest(low, lookback)
highestHigh = ta.highest(high, lookback)
longStop = (useStructure ? lowestLow : close) - atr * atrStopMultiplier
shortStop = (useStructure ? highestHigh : close) + atr * atrStopMultiplier
// Draw data to chart
plot(atr, color=color.rgb(33, 149, 243), title="ATR", display = display.none)
plot(longStop, color=color.green, title="Long Trailing Stop")
plot(shortStop, color=color.red, title="Short Trailing Stop")
var float LimitL = na
var float LimitS = na
var float LPosPrice = na
var float SPosPrice = na
var float LPosLongStop = na
var float SPosShortStop = na
KnowLimit (PosPrice, PosStop) =>
(PosPrice-PosStop)*LimitMultiplier+PosPrice
NotInTrade = strategy.position_size == 0
InLongTrade = strategy.position_size > 0
InShortTrade = strategy.position_size < 0
longCondition = TrendAlert > 0 and NotInTrade
if (longCondition)
LPosPrice := close
LPosLongStop := longStop
LimitL := KnowLimit(LPosPrice, LPosLongStop)
strategy.entry("long", strategy.long)
LTPPip = LimitL-LPosPrice
LSLPip = LPosPrice-longStop
alert(str.tostring(PineConnectorID)+',buy,'+str.tostring(CurrencyToSend)+',risk='+str.tostring(Risk)+',sl='+str.tostring(LSLPip)+'tp='+str.tostring(LTPPip), alert.freq_once_per_bar_close)
strategy.exit("exit", "long", stop = longStop, limit = LimitL)
shortCondition = TrendAlert < 0 and NotInTrade
if (shortCondition)
SPosPrice := close
SPosShortStop := shortStop
LimitS := KnowLimit(SPosPrice, SPosShortStop)
strategy.entry("short", strategy.short)
STPPip = SPosPrice-LimitS
SSLPip = shortStop - SPosPrice
alert(str.tostring(PineConnectorID)+',sell,ETHUSD,risk=10,sl='+str.tostring(SSLPip)+'tp='+str.tostring(STPPip), alert.freq_once_per_bar_close)
strategy.exit("exit", "short", stop = shortStop, limit = LimitS)
plotshape(longCondition, color = color.green, style = shape.labelup, location = location.belowbar, size = size.normal, title = "Long Condition")
plotshape(shortCondition, color = color.red, style = shape.labeldown, location = location.abovebar, size = size.normal, title = "Short Condition")
if (InShortTrade)
LimitL := close
LPosLongStop := close
LPosPrice := close
PlotLongTakeProfit = plot(LimitL, color = InLongTrade ? color.rgb(0, 255, 64) : color.rgb(120, 123, 134, 100), title = "Long Take Profit")
PlotLongStopLoss = plot(LPosLongStop, color = InLongTrade ? color.rgb(255, 0, 0) : color.rgb(120, 123, 134, 100), title = "Long Stop Loss")
PlotLongPosPrice = plot(LPosPrice, color = InLongTrade ? color.gray : color.rgb(120, 123, 134, 100), title = "Long Position Price")
if (InLongTrade)
LimitS := close
SPosShortStop := close
SPosPrice := close
PlotShortTakeProfit = plot(LimitS, color = InShortTrade ? color.rgb(0, 255, 64) : color.rgb(120, 123, 134, 100), title = "Short Take Profit")
PlotShortStopLoss = plot(SPosShortStop, color = InShortTrade ? color.rgb(255, 0, 0) : color.rgb(120, 123, 134, 100), title = "Short Stop Loss")
PlotShortPosPrice = plot(SPosPrice, color = InShortTrade ? color.gray : color.rgb(120, 123, 134, 100), title = "Short Position Price")
fill(PlotLongPosPrice, PlotLongTakeProfit, color = InLongTrade ? color.rgb(0, 255, 0, 95) : color.rgb(0, 255, 0, 100))
fill(PlotShortPosPrice, PlotShortTakeProfit, color = InShortTrade ? color.rgb(0, 255, 0, 95) : color.rgb(0, 255, 0, 100))
fill(PlotLongPosPrice, PlotLongStopLoss, color = InLongTrade ? color.rgb(255, 0, 0, 95) : color.rgb(255, 0, 0, 100))
fill(PlotShortPosPrice, PlotShortStopLoss, color = InShortTrade ? color.rgb(255, 0, 0, 95) : color.rgb(255, 0, 0, 100))