勢いを追跡し,傾向戦略

作者: リン・ハーンチャオチャン,日付: 2024-02-22 17:27:18
タグ:

img

概要

この戦略の主なアイデアは,スーパートレンド指標と平均方向運動指数 (ADX) を組み合わせてトレンドを判断し,追跡することです.スーパートレンド指標は現在の価格トレンド方向を特定するために使用され,ADXはトレンド強さを決定するために使用されます.取引は強いトレンド条件下でのみ行われます.また,戦略は確認のためにキャンドルスタックボディカラー,取引量,その他の指標も使用し,比較的完全な取引規則を構成します.

この戦略は,全体的に見ると,傾向を追跡する戦略に属し,中長期間の明確な傾向を把握し,統合と振動期間の干渉を避けることを目的としています.

戦略の原則

  1. スーパートレンド指標を使用して価格のトレンド方向を決定します.価格がスーパートレンドの上にあるとき,それは長い信号であり,スーパートレンドの下にあるとき,それは短い信号です.

  2. ADX を使ってトレンドの強さを判断する. ADX が値を超えるとのみ取引信号が生成されるので,不明確な収束期をフィルタリングすることができます.

  3. ろうそくのボディカラーは,現在上向きか下向きのパターンにあるかどうかを判断するために使用され,スーパートレンドインジケーターと組み合わせて確認されます.

  4. 取引量の拡大は確認信号として機能します.取引量が増加するときにのみポジションが確立されます.

  5. ストップ・ロスを設定し 利益を取り 利益とリスクを制御します

  6. 日が終わるまで 全てのポジションを閉じる

戦略 の 利点

  1. 中期と長期にわたる明確な傾向を追跡し,振動を回避し,高い収益性を達成します

  2. 戦略にはパラメータが少なく,理解し実行するのが簡単です.

  3. ストップ・ロストと 利益の確保により リスクはよくコントロールできます

  4. 確認のために複数の指標を使用することで 誤った信号を減らすことができます

戦略 の リスク

  1. 市場規模での大きな調整で大きな損失を被る可能性があります.

  2. 個々の株価は 基本値の変化により急激に逆転する可能性があります

  3. ブラック・スワン・イベントは 政策の大きな変化から

解決策:

  1. ADX パラメータを適切に調整し,強烈なトレンド下でのみ取引を確保する.

  2. ストップ・ロスの割合を増加させ,単一の損失額を制御する.

  3. 政策や重要な出来事を注意深く監視し 必要に応じて損失を積極的に削減します

最適化 に 関する 指示

  1. 最も安定した信号を生成するものを 探すことができます

  2. ADXパラメータの異なる組み合わせをテストして最適な設定を決定する.

  3. 波動性やボリンジャー帯などの他の確認指標を追加して 誤った信号をさらに減少させます

  4. トレンドが崩れるときに 損失を適時に削減するために ブレイクアウト戦略と組み合わせます

概要

この戦略の全体的な論理は明確で,スーパートレンドを使用して価格のトレンド方向を判断し,ADXを使用してトレンド強さを決定し,強いトレンドに沿って取引する.ストップ損失と利益を取ることはリスクを制御するために設定されています.この戦略にはパラメータがほとんどなく,最適化が簡単です.シンプルで効果的なトレンド追跡戦略を学ぶのに良い例として役立つことができます.パラメータ最適化,シグナルフィルタリングなどを通じてさらなる改善ができます.


/*backtest
start: 2023-02-15 00:00:00
end: 2024-02-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//Intraday Strategy Template

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © vikris

//@version=4
strategy("[VJ]Hulk Smash Intra", overlay=true, calc_on_every_tick = false, pyramiding=0,default_qty_type=strategy.percent_of_equity, default_qty_value=100,initial_capital=2000)

// ********** Strategy inputs - Start **********

// Used for intraday handling
// Session value should be from market start to the time you want to square-off 
// your intraday strategy
// Important: The end time should be at least 2 minutes before the intraday
// square-off time set by your broker
var i_marketSession = input(title="Market session", type=input.session, 
     defval="0915-1455", confirm=true)

// Make inputs that set the take profit % (optional)
longProfitPerc = input(title="Long Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01

shortProfitPerc = input(title="Short Take Profit (%)",
     type=input.float, minval=0.0, step=0.1, defval=1) * 0.01
     
// Set stop loss level with input options (optional)
longLossPerc = input(title="Long Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01

shortLossPerc = input(title="Short Stop Loss (%)",
     type=input.float, minval=0.0, step=0.1, defval=0.5) * 0.01    
     
var float i_multiplier = input(title = "ST Multiplier", type = input.float, 
     defval = 2, step = 0.1, confirm=true)

var int i_atrPeriod = input(title = "ST ATR Period", type = input.integer, 
     defval = 10, confirm=true)     
     
len = input(title="ADX Length", type=input.integer, defval=14)
th = input(title="ADX Threshold", type=input.integer, defval=20)
adxval = input(title="ADX Momemtum Value", type=input.integer, defval=25)     



// ********** Strategy inputs - End **********


// ********** Supporting functions - Start **********

// A function to check whether the bar or period is in intraday session
barInSession(sess) => time(timeframe.period, sess) != 0

// ********** Supporting functions - End **********


// ********** Strategy - Start **********

[superTrend, dir] = supertrend(i_multiplier, i_atrPeriod)

colResistance = dir == 1 and dir == dir[1] ? color.new(color.red, 0) : color.new(color.red, 100)
colSupport = dir == -1 and dir == dir[1] ? color.new(color.green, 0) : color.new(color.green, 100)


// Super Trend Long/short condition
stlong = close > superTrend
stshort = close < superTrend



// Figure out take profit price
longExitPrice  = strategy.position_avg_price * (1 + longProfitPerc)
shortExitPrice = strategy.position_avg_price * (1 - shortProfitPerc)

// Determine stop loss price
longStopPrice  = strategy.position_avg_price * (1 - longLossPerc)
shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc)

//Vol Confirmation
vol = volume > volume[1]


//Candles colors
greenCandle = (close > open)
redCandle = (close < open)

// See if intraday session is active
bool intradaySession = barInSession(i_marketSession)

// Trade only if intraday session is active




TrueRange = max(max(high - low, abs(high - nz(close[1]))), abs(low - nz(close[1])))
DirectionalMovementPlus = high - nz(high[1]) > nz(low[1]) - low ? max(high - nz(high[1]), 0) : 0
DirectionalMovementMinus = nz(low[1]) - low > high - nz(high[1]) ? max(nz(low[1]) - low, 0) : 0


SmoothedTrueRange = 0.0
SmoothedTrueRange := nz(SmoothedTrueRange[1]) - nz(SmoothedTrueRange[1]) / len + TrueRange
SmoothedDirectionalMovementPlus = 0.0
SmoothedDirectionalMovementPlus := nz(SmoothedDirectionalMovementPlus[1]) - 
   nz(SmoothedDirectionalMovementPlus[1]) / len + DirectionalMovementPlus
SmoothedDirectionalMovementMinus = 0.0
SmoothedDirectionalMovementMinus := nz(SmoothedDirectionalMovementMinus[1]) - 
   nz(SmoothedDirectionalMovementMinus[1]) / len + DirectionalMovementMinus

DIPlus = SmoothedDirectionalMovementPlus / SmoothedTrueRange * 100
DIMinus = SmoothedDirectionalMovementMinus / SmoothedTrueRange * 100
DX = abs(DIPlus - DIMinus) / (DIPlus + DIMinus) * 100
ADX = sma(DX, len)

// a = plot(DIPlus, color=color.green, title="DI+", transp=100)
// b = plot(DIMinus, color=color.red, title="DI-", transp=100)

//Final Long/Short Condition
longCondition = stlong and redCandle and vol and ADX>adxval
shortCondition = stshort and greenCandle and vol and ADX >adxval



//Long Strategy - buy condition and exits with Take profit and SL
if (longCondition and intradaySession)
    stop_level = longStopPrice
    profit_level = longExitPrice
    strategy.entry("My Long Entry Id", strategy.long)
    strategy.exit("TP/SL", "My Long Entry Id",stop=stop_level, limit=profit_level)
    


//Short Strategy - sell condition and exits with Take profit and SL
if (shortCondition and intradaySession)
    stop_level = shortStopPrice
    profit_level = shortExitPrice
    strategy.entry("My Short Entry Id", strategy.short)
    strategy.exit("TP/SL", "My Short Entry Id", stop=stop_level, limit=profit_level)
    
 
 
// Square-off position (when session is over and position is open)
squareOff = (not intradaySession) and (strategy.position_size != 0)
strategy.close_all(when = squareOff, comment = "Square-off")

// ********** Strategy - End **********

もっと