ドンチアン・チャネルとラリー・ウィリアムズ 大手貿易指数戦略

作者: リン・ハーンチャオチャン,日付: 2024年4月12日 17:27:25
タグ:

img

概要

この戦略は,ドンチアンチャンネル,ラリー・ウィリアムズ大貿易指数 (LWTI) とボリューム・ムービング・アベレージ (Volume Moving Average) の3つの指標を組み合わせて取引信号を生成する.価格がドンチアンチャンネル上部帯を超えるとロングポジションに入ります.価格がドンチアンチャンネル下部帯を超えるとショートポジションに入ります.価格がストップ・ロストまたは利益のレベルに達すると,または価格がドンチアンチャンネルの中部帯に戻るとポジションを退場します.同じトレンド方向への繰り返しエントリーを防ぐために,戦略はトレードカウンタを使用し,価格がドンチアンチャンネル中部帯を越えた後にのみ新規エントリーを許可します.

戦略原則

  1. ドンキアン・チャネル:価格が上位帯を突破すると長い信号が生成され,価格が下位帯を突破するとショート信号が生成されます.
  2. ラリー・ウィリアムズ・大手取引指数: ロングポジションはLWTIの色が緑色で,ショートポジションは赤色でしか許されない.
  3. 容量:現在の容量が容量移動平均値よりも大きい場合にのみエントリが許される.
  4. トレードカウンター:同じトレンド方向に繰り返しエントリを防ぐために,価格はドンチアン運河の中央帯を横断した後のみ新しいエントリが許可されます.
  5. ストップ・ロスとテイク・プロフィート: 入力時に,ストップ・ロスとテイク・プロフィートの距離はATRに基づいて計算され,テイク・プロフィートの距離はストップ・ロスの距離をリスク・リターン比に掛け算される.

戦略 の 利点

  1. 複数の指標を組み合わせて取引シグナルを確認することで,誤ったシグナルを効果的にフィルターし,シグナル品質を向上させることができます.
  2. ダイナミックストップ・ロースとテイク・プロフィート - ストップ・ロースとテイク・プロフィートの距離を変動に基づいて調整することで,戦略は市場の変化により良く適応できます.
  3. トレードカウンターは,同じトレンドを繰り返し入力するのを防止し,取引頻度を制御します.
  4. リスク/報酬比に基づく利益 - リスク/報酬比を前提に利益のレベルを設定することで,利益の可能性がリスクを上回ります.

戦略リスク

  1. パラメータリスク - 戦略のパフォーマンスは,異なるパラメータ設定によって大きく影響され,異なる市場特性と時間枠に基づいて最適化が必要です.
  2. 変動する市場リスク - 変動する市場条件では,頻繁に変動するため,戦略は頻繁にポジションに入ったり退場したりして,結果として業績が低下する可能性があります.
  3. トレンドリスク - トレンドが持続性がない場合,頻繁にエントリーとアウトプットが発生し,損失が増える可能性があります.
  4. ブラック・スワンリスク - 極端な市場状況では,指標が失敗し,戦略の業績が低下する可能性があります.

戦略の最適化方向

  1. パラメータの組み合わせを最適化するために,異なる楽器と時間枠のパラメータを最適化します.
  2. 動向平均値やモメント指標などのトレンドフィルタリング条件を追加し,トレンドが明確であるときにのみポジションを入力し,不安定な環境での取引数を減らす.
  3. 変動する市場条件にレンジブレイク戦略を使うことを検討します
  4. ストップ・ロスを最適化し,トライリング・ストップやその他の方法によって利益の論理を導入します.
  5. 極端な市場状況では,固定マネー管理と最大引き上げ制限の導入を検討してください.

概要

ドンチアンチャネルとラリー・ウィリアムズ大貿易指数戦略は,古典的なトレンドフォローする取引戦略である.ドンチアンチャネルを使用してトレンド方向を把握し,LWTI,ボリューム,その他の指標を使用してシグナルをフィルタリングし,厳格なリスク管理で動的なストップ損失と利益を引き出すことを採用する.全体として,これは安定したリターンの可能性のある戦略フレームワークである.しかし,この戦略はパラメータに敏感で,不安定な市場条件では不具合であることに注意する必要があります.トレンド市場での使用は推奨されています.実用的な応用では,良好で安定したリターンを達成するために,取引ツールと市場の特徴に基づいてパラメータと論理のさらなる最適化と厳格なマネジメントが必要です.


/*backtest
start: 2024-04-04 00:00:00
end: 2024-04-11 00:00:00
period: 1m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 
//at https://mozilla.org/MPL/2.0/
// © DillonGrech
//
//This is a Donchian Channel Trading Strategy which was found through the 
//YouTube channel TradingLab. 
//
//This Strategy uses the Donchian Channel, Larry Williams Large Trade Index,
//and Volume with Moving Average indicators for long and short trades.
//
//Strategy will enter based off indicator entry conditions and will not
//re-enter a trade until the price crosses through the Donchian Channel
//basis line (to prevent re-entering trades in same trend). Strategy will
//exit at stop loss or take profit, or when price crosses donchian basis.
//
//The strategy has been coded by Dillon Grech as part of his YouTube channel
//and a detailed video can be found on his channel at:
//https://www.youtube.com/c/DillonGrech
//https://www.youtube.com/watch?v=5IFe2Vjf61Y
//Source code and template files can be found on his GitHub at:
//https://github.com/Dillon-Grech
//==============================================================================
//@version=5
strategy("Donchian Channel Strategy [DillonGrech]", overlay=true, margin_long=100, margin_short=100)

//==============================================================================
//DONCHIAN CHANNEL
//==============================================================================
//Allow user to select whether they would like to use indicator
Don_Input = input(true, title='Use Donchian Channel?', group = "Donchian Settings")

//Indicator
don_length = input.int(96, minval = 1, group = "Donchian Settings")
don_lower  = ta.lowest(don_length)
don_upper  = ta.highest(don_length)
don_basis  = math.avg(don_upper, don_lower)
plot(don_basis,     "Don Basis", color = #FF6D00)
u = plot(don_upper, "Don Upper", color = #2962FF)
l = plot(don_lower, "Don Lower", color = #2962FF)
fill(u, l, color = color.rgb(33, 150, 243, 95), title = "Background")

//Conditions - Enter trades when there is a cross of price and previous donchian channel value
Ind_1_L = Don_Input == false ? false : ta.crossover(close,don_upper[1])
Ind_1_S = Don_Input == false ? false : ta.crossunder(close,don_lower[1])

//==============================================================================
//LARRY WILLIAMS LARGE TRADE INDEX (LWTI) - LOXX
//==============================================================================
//Allow user to select whether they would like to use indicator
LWTI_Input = input(true, title='Use LWTI?', group = "LWTI Settings")

//Indicator
greencolor = #2DD204
redcolor = #D2042D 

variant(type, src, len) =>
    sig = 0.0
    if type == "SMA"
        sig := ta.sma(src, len) 
    else if type == "EMA"
        sig := ta.ema(src, len) 
    else if type == "WMA"
        sig := ta.wma(src, len)   
    else if type == "RMA"
        sig := ta.rma(src, len)  
    sig
    
LWTI_per = input.int(25, "Period", group = "LWTI Settings")
LWTI_smthit = input.bool(false, "Smooth LWPI?", group = "LWTI Settings")
LWTI_type = input.string("SMA", "Smoothing Type", options = ["EMA", "WMA", "RMA", "SMA"], group = "LWTI Settings")
LWTI_smthper = input.int(20, "Smoothing Period", group = "LWTI Settings")

LWTI_ma = ta.sma(close - nz(close[LWTI_per]), LWTI_per)
LWTI_atr = ta.atr(LWTI_per)
LWTI_out = LWTI_ma/LWTI_atr * 50 + 50
LWTI_out := LWTI_smthit ? variant(LWTI_type, LWTI_out, LWTI_smthper) : LWTI_out

LWTI_colorout = LWTI_out > 50 ? greencolor : redcolor

//Conditions - Enter on color of indicator
Ind_2_L = LWTI_Input == false ? true : LWTI_colorout == greencolor
Ind_2_S = LWTI_Input == false ? true : LWTI_colorout == redcolor

//==============================================================================
//VOLUME INDICATOR
//==============================================================================
//Allow user to select whether they would like to use indicator
Vol_Input = input(true, title='Use Volume?', group = "Volume Settings")

//Indicator
Vol_Ma_Period = input.int(30,"Volume MA Period", group = "Volume Settings")
Vol_Ma = ta.sma(volume,Vol_Ma_Period)

//Conditions - Enter when volume is greater than moving average
Ind_3_L = Vol_Input == false ? true : volume > Vol_Ma
Ind_3_S = Vol_Input == false ? true : volume > Vol_Ma

//==============================================================================
//DONCHIAN CHANNEL TRADE COUNTER
//==============================================================================
//Stores whether a trade has been taken, and resets when there is a cross of price and donchain basis
Trade_Counter = float(0)
Don_Basis_Cross = ta.cross(don_basis[1], close)
if strategy.position_size!=0
    Trade_Counter := 1
else if Don_Basis_Cross
    Trade_Counter := 0
else 
    Trade_Counter := Trade_Counter[1]

Plot_Trade_Counter = input.bool(false, "Plot Trade Position Counter?", group = "Plot Settings")
plotchar(Plot_Trade_Counter and Trade_Counter == 0 ? true : false, color = na, text = '0')
plotchar(Plot_Trade_Counter and Trade_Counter == 1 ? true : false, color = na, text = '1')

//==============================================================================
//ENTRY CONDITIONS
//==============================================================================
entry_long  = strategy.position_size<=0 and Ind_1_L and Ind_2_L and Ind_3_L and Trade_Counter[1] == 0
entry_short = strategy.position_size>=0 and Ind_1_S and Ind_2_S and Ind_3_S and Trade_Counter[1] == 0

if(entry_long)
    strategy.entry("Long Entry", strategy.long)
if(entry_short)
    strategy.entry("Short Entry", strategy.short)

//==============================================================================
// TAKE PROFIT AND STOP LOSS CONDITIONS
//==============================================================================
Stop_Input   = input(true, title='Use Stop Loss?', group = "Risk Settings")
Profit_Input = input(true, title='Use Take Profit?', group = "Risk Settings")
Profit_RR = input.float(2.0,"Risk Reward Profit Target", group = "Risk Settings")

//Store Price on new entry signal
Entry_Price = strategy.opentrades.entry_price(strategy.opentrades - 1)

//Store Donchain Channel Basis value on new entry signal
Entry_Don_Basis = float(0.0)
if strategy.position_size == 0 or entry_long or entry_short
    Entry_Don_Basis := don_basis
else
    Entry_Don_Basis := Entry_Don_Basis[1]

//Get stop loss distance
Stop_Distance = math.abs(Entry_Price - Entry_Don_Basis)*1.02

//For Long Trades, find the stop loss level
Stop_L = float(0.0)
if Stop_Input == true
    Stop_L := Entry_Price - Stop_Distance
else
    na

//For Long Trades, find the profit level
Profit_L = float(0.0)
if Profit_Input == true
    Profit_L := Entry_Price + Stop_Distance*Profit_RR
else
    na

//For Short Trades, find the stop loss level
Stop_S = float(0.0)
if Stop_Input == true
    Stop_S   := Entry_Price + Stop_Distance
else
    na

//For Short Trades, find the profit level
Profit_S = float(0.0)
if Profit_Input == true
    Profit_S := Entry_Price - Stop_Distance*Profit_RR
else
    na

//Plot profit and stop loss levels for long and short trades
plot(strategy.position_size > 0 ? Profit_L : na, color=color.lime, style=plot.style_linebr, linewidth=2)
plot(strategy.position_size > 0 ? Stop_L : na,   color=color.red,  style=plot.style_linebr, linewidth=2)
plot(strategy.position_size < 0 ? Profit_S : na, color=color.lime, style=plot.style_linebr, linewidth=2)
plot(strategy.position_size < 0 ? Stop_S : na,   color=color.red,  style=plot.style_linebr, linewidth=2)

//==============================================================================
//EXIT ORDERS
//==============================================================================
//Exit long trades
if Stop_Input
    strategy.exit(id = 'Exit Long', from_entry ='Long Entry', comment='Long Stop',  stop = Stop_L)

if Profit_Input
    strategy.exit(id = 'Exit Long', from_entry ='Long Entry', comment='Long Profit', limit = Profit_L)

//Exit short trades
if Stop_Input
    strategy.exit(id = 'Exit Short', from_entry ='Short Entry', comment='Short Stop', stop = Stop_S)

if Profit_Input
    strategy.exit(id = 'Exit Short', from_entry ='Short Entry', comment='Short Profit', limit = Profit_S)

//==============================================================================
//CLOSE ORDERS
//==============================================================================
exit_long  = close < don_basis
exit_short = close > don_basis

if(exit_long)
    strategy.close("Long Entry", comment='Long Close', qty_percent=100)
if(exit_short)
    strategy.close("Short Entry", comment='Short Close', qty_percent=100)

もっと