
多層目標と尾行ストップ戦略は,市場動態を捕捉し,利益を保護するために設計されたハイネンシーチャートモデルに基づくトレンド追跡システムである.この戦略は,最初の入場と二次入場 (ピラミッド式加仓) を許可し,各入場ごとに独立した利益目標と尾行ストップの設定がある.それは,利益の可能性を拡大するためにダイナミックな目標領域を使用し,価格が有利な方向に動くと利益をロックする柔軟な尾行ストップシステムを実装する.
この戦略は,いくつかの重要な原則に基づいています.
ハイン・アンシー・マップ信号: ハイン・アンシー・グラフを使用して市場のノイズをフィルターし,トレンドを識別する.多頭信号は,現在のHAの閉盘価格がHAの開盘価格より高く,以前のHAの閉盘価格よりも高いときに誘発される.空頭信号は,その逆である.
双層の入場システム:
破綻したバランス保護: 最初の目標を達成すると,戦略は自動的にストップ・ロスを入場価格 (利平衡点) に移動し,取引が損なわれないようにします.
ターゲットエリアの概念: 価格がターゲットレベルに近づくと (前定義の値内) 戦略は”ターゲット領域”を起動し,より多くの潜在的な利益をキャプチャするためにターゲットレベルを上昇させる
尾行停止メカニズム:
ステータストラッキング戦略:取引の方向,価格のピーク,最初の目標の達成,現在目標領域にあるかなどを追跡する複数の変数を維持する
リスクの管理この戦略は,先制のストップ,負債のバランス保護,追随のストップを設定することで,多層のリスク管理を提供し,資本を大幅な下落から保護する.
ピラミッドの利回り: 二次入場を許容することで,戦略は,確認されたトレンドの中でポジションを増やし,利益の潜在性を高めることができ,同時に,最初の取引が既に損益平衡点にロックされているため,全体的なリスクを増加させない.
ダイナミックな利益捕獲: ターゲットの領域とターゲットの増幅機能により,戦略は強気な市場において,強気なトレンドから早めに脱却するのではなく,自動的に利益目標を拡大することができます.
高さも調整できます: 戦略は,市場条件,取引品種特性,個人リスクの好みに応じてトレーダーに調整できるように,幅広いパラメータ設定を提供します.
自動実行: パラメータ設定が完了すると,戦略はすべての入場,出場,ストップ・ローズ調整を実行し,感情取引の影響を排除する.
視覚的なフィードバック戦略には,ターゲットレベル,ストップ・ローズレベル,現在の状態の指標を表示する明確なビジュアル構成要素が含まれているため,トレーダーは取引の進行を容易に監視できます.
パラメータ感度戦略の性能は,パラメータ設定に大きく依存している. 目標やストップのパラメータが不適切である場合,早めに良好な取引から離脱したり,過度の下落のリスクを背負ったりする可能性があります. 歴史の回顧と市場特有のパラメータの最適化によって,このリスクを軽減することができます.
スリッページリスク: 特に尾行ストップの実行中に,市場のギャップまたは流動性の不足が,実際の実行価格と理想のストップレベルとの差異を引き起こす可能性がある.滑り場の緩衝を増やすか,より保守的な尾行パラメータを使用することを考慮することで,このリスクを軽減することができます.
過剰取引の再入場:二次エントリーを有効にすることは,不安定な市場における過度取引につながる可能性があります.追加のフィルタリング条件または二次エントリー時間制限の導入は,このような事態を減らすことができます.
市場転換のリスク: 戦略はトレンド市場ではうまく機能しますが,区間振動市場または突然のターニングの市場ではうまく機能しない可能性があります. 戦略と市場状態フィルターの組み合わせを使用すると,全体的な効果が向上します.
計算密度: 複数の変数と状態を追跡する戦略で,一部のプラットフォームでは実行の遅延を引き起こす可能性があります. コードを最適化し,一部の計算を簡素化することでパフォーマンスを向上させることができます.
トレンドフィルターを追加: 統合されたトレンド指標 (移動平均,ADX,またはトレンド強度指標など) は,入場品質を向上させ,確認されたトレンド方向のみで取引する.これは,振動市場における誤信号を減らすだろう.
タイムフィルター条件を導入する: 二次入場のための時間窓や冷却期を追加し,短期間で過度取引や同じトレンドの頻繁な入出を防ぐ.
波動性調整: 市場変動 (ATRなど) に基づいて目標とストップ・ローズパラメータを動的に調整することで,戦略を異なる市場条件に適応させることができる.これは,ストップ・ローズとターゲットレベルを現在の市場特性により適合させるだろう.
ハイン・アンシー論理の改良: 現在のHA判断は比較的簡単で,多根HA図形またはHA動力の指標を考慮して信号の質を高めることができる.
収益を部分的に固定する: 利潤保護と潜在的利益の最大化とのバランスを保って,特定の利潤レベルに達したときに部分的なポジションを平衡させ,残りの部分を継続させることを可能にする分期利潤ロック機能の導入.
目標領域の論理を最適化する: 現時点のターゲット地域は固定増加歩長を使用する. 市場の波動性や最近の価格動向に基づいて動的なターゲット調整アルゴリズムを考慮して,市場条件の変化により適した調整を行うことができる.
多層目標と尾行停止戦略は,ハイアンシー・トレンド識別,ダイナミック・ターゲット・マネジメント,二次エントリー・チャンス,多層リスク・コントロールを組み合わせた総合的な取引システムである.この戦略の主要な優点は,その柔軟な利益拡大機構と厳格なリスク管理フレームワークであり,トレンド市場における顕著な動きを捉えるのに適している.
この戦略は強力な枠組みを提供しているものの,その有効性は適切なパラメータ調整と市場条件に依存している.市場状態のフィルター,波動性調整機構,より複雑な入場確認ロジックを追加することで,この戦略はさらにその堅強さと適応性を強化することができる.最終的には,この戦略は,トレンドを最大限に捉えようとしながら,システム化されたリスク管理によって取引資本を保護するバランスを表現する.
/*backtest
start: 2024-03-31 00:00:00
end: 2025-03-29 08:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Algo Trading v1 | SUNNY GUHA By OIESU", overlay=true, margin_long=100, margin_short=100, pyramiding=100)
// ———— USER INPUTS ———— //
// First Entry Settings
float initialTarget = input.float(10000, "First Entry: Target ($)", minval=1, tooltip="First target level")
float initialStopLoss = input.float(3000, "First Entry: Stop Loss ($)", minval=1, tooltip="Initial stop loss distance")
bool useTrailFirst = input.bool(true, "First Entry: Enable Trail", tooltip="Enable trailing features after first target hit")
float profitTrailStepFirst = input.float(1500, "First Entry: Trail Amount ($)", minval=1, tooltip="Trail amount after first target hit")
bool useTargetZoneFirst = input.bool(true, "First Entry: Enable Target Zone", tooltip="Enable target zone feature")
float targetZoneThresholdFirst = input.float(1000, "First Entry: Target Zone Threshold ($)", minval=1, tooltip="Distance to activate target zone")
float targetIncreaseStepFirst = input.float(2000, "First Entry: Target Increase ($)", minval=1, tooltip="Amount to increase target")
// Second Entry Settings
bool enableSecondEntries = input.bool(true, "Enable Second Entries", tooltip="Allow re-entries after first target hit")
float secondTarget = input.float(5000, "Second Entry: Target ($)", minval=1, tooltip="Target for second entries")
float secondStopLoss = input.float(2000, "Second Entry: Stop Loss ($)", minval=1, tooltip="Stop loss for second entries")
bool useTrailSecond = input.bool(true, "Second Entry: Enable Trail", tooltip="Enable trailing for second entries")
float profitTrailStepSecond = input.float(1500, "Second Entry: Trail Amount ($)", minval=1, tooltip="Trail amount for second entries")
bool useTargetZoneSecond = input.bool(true, "Second Entry: Enable Target Zone", tooltip="Enable target zone")
float targetZoneThresholdSecond = input.float(1000, "Second Entry: Target Zone Threshold ($)", minval=1)
float targetIncreaseStepSecond = input.float(2000, "Second Entry: Target Increase ($)", minval=1)
// ———— HEIKIN-ASHI CALCULATIONS ———— //
var float haOpen = na
var float haClose = na
var float haHigh = na
var float haLow = na
haClose := (open + high + low + close)/4
haOpen := na(haOpen[1]) ? (open + close)/2 : (haOpen[1] + haClose[1])/2
haHigh := math.max(high, math.max(haOpen, haClose))
haLow := math.min(low, math.min(haOpen, haClose))
// ———— TRACKING VARIABLES ———— //
var float highestPrice = na // Tracks highest price for long positions
var float lowestPrice = na // Tracks lowest price for short positions
var float basePrice = na // Entry price for position
var float targetLevel = na // Current target level
var float stopLevel = na // Current stop level
var bool firstTargetHit = false // Indicates if first target was hit
var string tradeDirection = "none" // Current trade direction
var bool isSecondEntry = false // Tracks if current position is a second entry
var bool inTargetZone = false // Tracks if price is in target zone
// ———— SIGNAL DETECTION ———— //
bullish = haClose > haOpen and haClose > haClose[1]
bearish = haClose < haOpen and haClose < haClose[1]
// Entry conditions - only allow second entries if enabled and after first target hit
longCondition = bullish and (tradeDirection != "long" or (enableSecondEntries and firstTargetHit))
shortCondition = bearish and (tradeDirection != "short" or (enableSecondEntries and firstTargetHit))
// Position Management - Long Positions
if strategy.position_size > 0
highestPrice := math.max(high, nz(highestPrice, high))
if isSecondEntry
// Second Entry Management
inTargetZone := useTargetZoneSecond and high >= targetLevel - targetZoneThresholdSecond
if inTargetZone and useTargetZoneSecond
targetLevel := targetLevel + targetIncreaseStepSecond
if useTrailSecond
stopLevel := math.max(stopLevel, highestPrice - profitTrailStepSecond)
if low <= stopLevel
strategy.close_all("Second Entry Stop")
basePrice := na
targetLevel := na
stopLevel := na
highestPrice := na
lowestPrice := na
firstTargetHit := false
isSecondEntry := false
inTargetZone := false
tradeDirection := "none"
else
// First Entry Management - improved profit locking
if not firstTargetHit and high >= basePrice + initialTarget
// First target hit - ALWAYS lock profit at break-even
firstTargetHit := true
stopLevel := basePrice // Move stop to break-even
targetLevel := useTrailFirst ? high + targetIncreaseStepFirst : basePrice + initialTarget
else if firstTargetHit
// Only modify target if trailing is enabled
if useTrailFirst
inTargetZone := useTargetZoneFirst and high >= targetLevel - targetZoneThresholdFirst
if inTargetZone and useTargetZoneFirst
targetLevel := targetLevel + targetIncreaseStepFirst
// Trail stop-loss but never below break-even
stopLevel := math.max(basePrice, highestPrice - profitTrailStepFirst)
else
// Before first target hit
targetLevel := basePrice + initialTarget
stopLevel := basePrice - initialStopLoss
// Exit on stop hit - this could only be at break-even or better after first target
if low <= stopLevel
strategy.close_all("First Entry Stop")
basePrice := na
targetLevel := na
stopLevel := na
highestPrice := na
lowestPrice := na
firstTargetHit := false
isSecondEntry := false
inTargetZone := false
tradeDirection := "none"
// Position Management - Short Positions
if strategy.position_size < 0
lowestPrice := math.min(low, nz(lowestPrice, low))
if isSecondEntry
// Second Entry Management
inTargetZone := useTargetZoneSecond and low <= targetLevel + targetZoneThresholdSecond
if inTargetZone and useTargetZoneSecond
targetLevel := targetLevel - targetIncreaseStepSecond
if useTrailSecond
stopLevel := math.min(stopLevel, lowestPrice + profitTrailStepSecond)
if high >= stopLevel
strategy.close_all("Second Entry Stop")
basePrice := na
targetLevel := na
stopLevel := na
highestPrice := na
lowestPrice := na
firstTargetHit := false
isSecondEntry := false
inTargetZone := false
tradeDirection := "none"
else
// First Entry Management - improved profit locking
if not firstTargetHit and low <= basePrice - initialTarget
// First target hit - ALWAYS lock profit at break-even
firstTargetHit := true
stopLevel := basePrice // Move stop to break-even
targetLevel := useTrailFirst ? low - targetIncreaseStepFirst : basePrice - initialTarget
else if firstTargetHit
// Only modify target if trailing is enabled
if useTrailFirst
inTargetZone := useTargetZoneFirst and low <= targetLevel + targetZoneThresholdFirst
if inTargetZone and useTargetZoneFirst
targetLevel := targetLevel - targetIncreaseStepFirst
// Trail stop-loss but never above break-even
stopLevel := math.min(basePrice, lowestPrice + profitTrailStepFirst)
else
// Before first target hit
targetLevel := basePrice - initialTarget
stopLevel := basePrice + initialStopLoss
// Exit on stop hit - this could only be at break-even or better after first target
if high >= stopLevel
strategy.close_all("First Entry Stop")
basePrice := na
targetLevel := na
stopLevel := na
highestPrice := na
lowestPrice := na
firstTargetHit := false
isSecondEntry := false
inTargetZone := false
tradeDirection := "none"
// New Position Entry
if strategy.position_size == 0
if longCondition
tradeDirection := "long"
basePrice := close
targetLevel := basePrice + (firstTargetHit ? secondTarget : initialTarget)
stopLevel := basePrice - (firstTargetHit ? secondStopLoss : initialStopLoss)
highestPrice := high
isSecondEntry := firstTargetHit
strategy.entry("Long", strategy.long)
else if shortCondition
tradeDirection := "short"
basePrice := close
targetLevel := basePrice - (firstTargetHit ? secondTarget : initialTarget)
stopLevel := basePrice + (firstTargetHit ? secondStopLoss : initialStopLoss)
lowestPrice := low
isSecondEntry := firstTargetHit
strategy.entry("Short", strategy.short)
// ———— VISUALIZATION ———— //
// Entry signals
plotshape(longCondition and (strategy.position_size == 0), title="Buy", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(shortCondition and (strategy.position_size == 0), title="Sell", style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Target and stop levels with clearer colors
plot(targetLevel, title="Target Level", color=color.orange, linewidth=2)
plot(stopLevel, title="Stop Level", color=color.red, linewidth=2)
// Break-even level - shown prominently after first target hit
plot(strategy.position_size != 0 and firstTargetHit ? basePrice : na, title="Break-Even Level", color=color.green, linewidth=2, style=plot.style_linebr)
// Debug plots for state tracking
plotchar(firstTargetHit, title="First Target Hit", char="T", location=location.top, color=color.yellow, size=size.tiny)
plotchar(isSecondEntry, title="Second Entry", char="2", location=location.top, color=color.white, size=size.tiny)
plotchar(useTrailFirst and firstTargetHit, title="Trail Active", char="→", location=location.top, color=color.blue, size=size.tiny)
plotchar(inTargetZone, title="Target Zone", char="Z", location=location.top, color=color.fuchsia, size=size.tiny)