複数のSMA範囲の突破と動的利益ロック定量取引戦略

SMA
作成日: 2024-12-20 16:28:54 最終変更日: 2024-12-20 16:28:54
コピー: 0 クリック数: 441
1
フォロー
1617
フォロワー

複数のSMA範囲の突破と動的利益ロック定量取引戦略

概要

これは,SMA指数に基づく動的トレンド追跡取引戦略で,価格区間,ランダム指数,多重利益保護機構を組み合わせている.この戦略は,短期と長期の移動平均の交差信号を組み合わせて,価格の動きを監視し,市場状態とトレンドの強さを決定するためにランダム指数を使用して効率的なトレンドキャプチャを実現する.この戦略は,パーセントと固定数の両方のストップメカニズムを設計し,利益とリスクを効果的にバランスします.

戦略原則

戦略の中核となるロジックには、次の主要な部分が含まれます。

  1. 19サイクルと74サイクルSMAを使ってトレンドフレームを構築する
  2. 60サイクルランダムな指標によって市場の状態を判断し,SMAの色を黄色,緑,赤,の4つの状態に分ける
  3. 価格の強さや弱さを見極めるために,価格区間を5つの重要なレベルに分けます.
  4. 入場条件は同時に満たす必要があります:
    • 緑色または黄色で表示されます.
    • 価格がオレンジ圏を突破した
    • 短期 SMA 以上の終盤価格
  5. この2つの停止装置は,
    • 最高価格に基づく保護率の撤回
    • 固定ポイントに基づく利益ロック

戦略的優位性

  1. マルチ認証メカニズムが偽信号を低減する
  2. ダイナミックな区分は,異なる市場環境に対応します.
  3. ダブル・ストップ・メカニズムにより,よりよいリスク管理が可能
  4. 市場状況の明確な分類は,市場のペースを把握するのに役立ちます.
  5. リアルタイムで取引状況を監視し,戦略の調整を容易にします.
  6. 技術指標と価格行動分析を組み合わせた

戦略リスク

  1. 市場が揺れ動いていると 過剰取引が起こりうる
  2. 固定点数止まりは,大事件を逃しているかもしれない.
  3. パラメータの最適化は過剰適合につながる可能性がある
  4. 市場が急転すると,利益の一部が失われる可能性がある.
  5. 複数の確認条件により,取引の機会の一部が逃れている可能性があります. 解決策は
  • 波動率のフィルターに追加
  • 動的に停止参数調整
  • 市場環境識別メカニズムの強化
  • 試合のタイミングを最適化する

戦略最適化の方向性

  1. 波動率指標の動的調整パラメータを導入する
  2. 市場状況に応じて自律的に停止条件を調整する
  3. 取引量確認メカニズムの追加
  4. トレンド強度フィルターを追加
  5. 市場特性を考慮して,区画を最適化
  6. リスク管理の改善
    • 日常のストップ
    • 最大撤回制御
    • ポジションの時間制限

要約する

この戦略は,複数の技術指標と価格行動分析方法の総合的な適用によって,完全な取引システムを構築している.戦略の優点は,複数の確認機構と柔軟な停止システムにあるが,市場環境が戦略のパフォーマンスに与える影響にも注意する必要がある.継続的な最適化とリスク管理の改善により,戦略は,異なる市場環境で安定したパフォーマンスを維持する見込みがある.

ストラテジーソースコード
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy(title="SMA Color Strategy", 
     overlay=true, 
     initial_capital=10000,
     max_bars_back=5000,
     max_labels_count=500,
     max_boxes_count=500,
     default_qty_type=strategy.fixed,
     default_qty_value=1,
     currency=currency.NONE,
     process_orders_on_close=true)

// === INPUTS ===
zoneLength = input.int(20, "Price Zone Length", minval=5)
profitLockPct = input.float(50, "Profit Lock Percentage", minval=1, maxval=100, step=5) / 100
ticksToLock = input.int(12, "Ticks to Activate Lock", minval=1, tooltip="Number of ticks price must move up to activate tick-based lock")
ticksToSecure = input.int(10, "Ticks to Secure", minval=1, tooltip="Number of ticks to lock in once activated")

// Calculate tick values
tickSize = syminfo.mintick
ticksToLockPoints = ticksToLock * tickSize
ticksToSecurePoints = ticksToSecure * tickSize

// Calculate price zones
h = ta.highest(high, zoneLength)
l = ta.lowest(low, zoneLength)
priceRange = h - l
lvl5 = h
lvl4 = l + (priceRange * 0.75)  // Orange line
lvl3 = l + (priceRange * 0.50)  // Yellow line
lvl2 = l + (priceRange * 0.25)  // Green line
lvl1 = l

// Calculate SMAs
sma19 = ta.sma(close, 19)
sma74 = ta.sma(close, 74)

// Stochastic calculation for color logic
k = ta.stoch(close, high, low, 60)
d = ta.sma(k, 10)

// SMA Color Logic with state tracking
var color currentSMAColor = color.orange
var color previousSMAColor = color.orange
var string currentColorName = "ORANGE"
var string previousColorName = "ORANGE"

smaColor = if d >= 80 or d <= 20
    color.rgb(255, 215, 0)
else if d > d[1]
    color.green
else if d < d[1]
    color.red
else
    color.orange

// Update color state and names
if smaColor != currentSMAColor
    previousSMAColor := currentSMAColor
    currentSMAColor := smaColor
    previousColorName := currentColorName
    currentColorName := if smaColor == color.rgb(255, 215, 0)
        "YELLOW"
    else if smaColor == color.green
        "GREEN"
    else if smaColor == color.red
        "RED"
    else
        "ORANGE"

// Color logic for SMA74
sma74Color = if smaColor == color.rgb(255, 215, 0)
    color.rgb(255, 215, 0)                          
else if sma74 < sma19                               
    color.green
else                                                
    color.red

// === ENTRY CONDITIONS ===
smaIsGreen = smaColor == color.green
greenCandle = close > open
candleAboveOrange = close > lvl4
candleAboveSMA = close > sma19
crossedAboveOrange = ta.crossover(close, lvl4)
smaIsYellow = smaColor == color.rgb(255, 215, 0)

longCondition1 = smaIsGreen and greenCandle and candleAboveOrange and candleAboveSMA and crossedAboveOrange
longCondition2 = smaIsYellow and crossedAboveOrange and candleAboveSMA

// === PROFIT LOCK SYSTEM ===
var float entryPrice = na
var float maxPrice = na
var float profitLockLevel = na
var bool tickLockActivated = false
var float tickBasedLockLevel = na

// Reset variables on new trade entry
if (longCondition1 or longCondition2)
    entryPrice := close
    maxPrice := close
    profitLockLevel := close * (1 - profitLockPct)
    tickLockActivated := false
    tickBasedLockLevel := na

// Update maximum price and profit locks when in a trade
if strategy.position_size > 0
    maxPrice := math.max(maxPrice, high)
    profitLockLevel := math.max(profitLockLevel, maxPrice * (1 - profitLockPct))
    
    // Check if price has moved up enough to activate tick-based lock
    if not tickLockActivated and (maxPrice - entryPrice) >= ticksToLockPoints
        tickLockActivated := true
        tickBasedLockLevel := entryPrice + ticksToSecurePoints

// === EXIT CONDITIONS ===
exitOnYellowLine = close < lvl3
exitOnProfitLock = low < profitLockLevel and strategy.position_size > 0
exitOnTickLock = tickLockActivated and low < tickBasedLockLevel

// === TRADE MANAGEMENT ===
if (longCondition1 or longCondition2)
    strategy.entry("Long", strategy.long)

if strategy.position_size > 0
    if exitOnYellowLine
        strategy.close("Long", comment="Close below yellow")
    if exitOnProfitLock
        strategy.close("Long", comment="Profit lock triggered")
    if exitOnTickLock
        strategy.close("Long", comment="Tick-based lock triggered")

// Plot indicators
plot(sma19, "SMA 19", color=smaColor, linewidth=2)
plot(sma74, "SMA 74", color=sma74Color, linewidth=2)
plot(lvl5, "Upper Zone Top", color=color.red, linewidth=2)
plot(lvl4, "Upper Zone Bottom", color=color.orange, linewidth=2)
plot(lvl3, "Middle Line", color=color.yellow, linewidth=2)
plot(lvl2, "Lower Zone Top", color=color.green, linewidth=2)
plot(lvl1, "Lower Zone Bottom", color=color.blue, linewidth=2)

// Plot profit lock levels
plot(strategy.position_size > 0 ? profitLockLevel : na, "Profit Lock Level", color=color.purple, style=plot.style_linebr, linewidth=2)
plot(strategy.position_size > 0 and tickLockActivated ? tickBasedLockLevel : na, "Tick Lock Level", color=color.fuchsia, style=plot.style_linebr, linewidth=2)

// Fill zones
var p1 = plot(lvl5, display=display.none)
var p2 = plot(lvl4, display=display.none)
var p3 = plot(lvl2, display=display.none)
var p4 = plot(lvl1, display=display.none)
fill(p1, p2, color=color.new(color.red, 90))
fill(p3, p4, color=color.new(color.green, 90))

// Debug Table
if barstate.islast
    var table debugTable = table.new(position.top_right, 2, 13, bgcolor=color.new(color.black, 70), frame_width=1)
    
    table.cell(debugTable, 0, 0, "Current Color", text_color=color.white)
    table.cell(debugTable, 1, 0, currentColorName, text_color=currentSMAColor)
    
    table.cell(debugTable, 0, 1, "Previous Color", text_color=color.white)
    table.cell(debugTable, 1, 1, previousColorName, text_color=previousSMAColor)
    
    table.cell(debugTable, 0, 2, "Entry 1 (Green)", text_color=color.white)
    table.cell(debugTable, 1, 2, str.tostring(longCondition1), text_color=color.white)
    
    table.cell(debugTable, 0, 3, "Entry 2 (Yellow)", text_color=color.white)
    table.cell(debugTable, 1, 3, str.tostring(longCondition2), text_color=color.white)
    
    table.cell(debugTable, 0, 4, "Current Position", text_color=color.white)
    table.cell(debugTable, 1, 4, str.tostring(strategy.position_size), text_color=color.white)
    
    table.cell(debugTable, 0, 5, "Entry Price", text_color=color.white)
    table.cell(debugTable, 1, 5, str.tostring(entryPrice), text_color=color.white)
    
    table.cell(debugTable, 0, 6, "Max Price", text_color=color.white)
    table.cell(debugTable, 1, 6, str.tostring(maxPrice), text_color=color.white)
    
    table.cell(debugTable, 0, 7, "Profit Lock Level", text_color=color.white)
    table.cell(debugTable, 1, 7, str.tostring(profitLockLevel), text_color=color.white)
    
    table.cell(debugTable, 0, 8, "Tick Lock Active", text_color=color.white)
    table.cell(debugTable, 1, 8, str.tostring(tickLockActivated), text_color=color.white)
    
    table.cell(debugTable, 0, 9, "Tick Lock Level", text_color=color.white)
    table.cell(debugTable, 1, 9, str.tostring(tickBasedLockLevel), text_color=color.white)
    
    table.cell(debugTable, 0, 10, "Price Move (Ticks)", text_color=color.white)
    table.cell(debugTable, 1, 10, str.tostring(strategy.position_size > 0 ? (maxPrice - entryPrice) / tickSize : 0), text_color=color.white)
    
    table.cell(debugTable, 0, 11, "Locked Profit %", text_color=color.white)
    table.cell(debugTable, 1, 11, str.tostring(strategy.position_size > 0 ? ((maxPrice - entryPrice) / entryPrice * 100) : 0.0) + "%", text_color=color.white)
    
    table.cell(debugTable, 0, 12, "Exit Signals", text_color=color.white)
    table.cell(debugTable, 1, 12, "Y:" + str.tostring(exitOnYellowLine) + " P:" + str.tostring(exitOnProfitLock) + " T:" + str.tostring(exitOnTickLock), text_color=color.white)