ラリー・ウィリアムズの移動平均のクロスオーバー戦略

作者: リン・ハーンチャオチャン開催日:2023年12月26日 15:03:16
タグ:

img

概要

これは,有名なトレーダーであるラリー・ウィリアムズによって作成されたシンプルでクラシックな移動平均クロスオーバー戦略である.この戦略は,9日間のシンプル移動平均を高速線と21日間の指数関数移動平均をスローラインとして使用する.価格は9日間の線を超えると長くなり,価格が9日間の線を下回ると短くなります.偽のブレイクをフィルタリングするために,21日間の線もトレンドを確認するために使用されます.

戦略の論理

この戦略は,長期と短期の機会を決定するために移動平均のゴールデンクロスオーバーとデッドクロスオーバーに基づいています. 速い線が下からスローラインを越えると,それはゴールデンクロスオーバーで,上昇傾向への変化を示します. このようなブレイクアウトは,ロングに行くために使用されます. 速い線が上からスローラインを下に突破すると,それはデッドクロスオーバーで,低下傾向への変化を示します. このようなブレイクアウトは,ショートに行くために使用されます.

虚拟損失につながる偽ブレイクを避けるために,21日線も主要なトレンドを決定するために使用されます. 急速線がブレイクされ,価格も21日線を突破した場合のみ,取引行動が行われます. これにより多くの偽ブレイクを効果的にフィルタリングすることができます.

具体的には,長信号は,高速線が昨日の高値を超えて21日線を超えると起動します.短信号は,高速線が昨日の低値を超えて21日線を超えると起動します.

利点分析

この戦略の主な利点は以下の通りです.

  1. 戦略のアイデアは単純で理解し実行するのが簡単です
  2. 移動平均の技術は成熟し,広く使用されています.
  3. 21日線を導入することで 誤ったブレイクを効果的にフィルタリングできます
  4. 昨日の極点を利用して ポジションに入れるなら 罠にはまりません
  5. 戦略パラメータは比較的堅牢で 簡単にオーバーフィットしません

リスク分析

この戦略の主なリスクは,

  1. 不安定な市場では 移動平均値が遅れて 最良のエントリーポイントを逃す可能性があります
  2. 価格が横向きに動いている範囲限定市場では,頻繁に小規模な損失が発生することがあります.
  3. 突然の出来事や 傾向の変化に 効果的に対応できないのです

これらのリスクに対処するために,次の側面で最適化を行うことができます:

  1. MACDインジケーターを導入し リアルタイム信号を増やします
  2. MA 期間パラメータを増加させ,取引頻度を下げる.
  3. ストップロスの戦略を追加して,単一の取引損失額を制御します.

オプティマイゼーションの方向性

この戦略の主要な最適化方向は以下の通りである.

  1. パラメータ最適化.より体系的な方法により,よりよいパラメータを見つけるために異なるMA期間の組み合わせをテストすることができる.

  2. 適切な移動ストップ損失,パーセントストップ損失などを設定して,単一の取引損失を効果的に制御します.

  3. 他の指標を組み合わせ,MACD,ATR,KDなどからの信号を導入して,より多くの確認次元を得,戦略の安定性を向上させる.

  4. 退出メカニズムを最適化します.逆信号出口,移動利益取出口など,さまざまな種類の退出方法を研究します.

結論

概要すると,この移動平均クロスオーバー戦略は,非常に典型的で実践的なトレンドフォロー戦略です.理解し,実装しやすく,改善の余地があるという利点があります.パラメータ最適化,ストップ損失最適化,マルチインジケーター組み合わせなどの方法によって,より安定的かつ実践的な取引システムに変えるために継続的な改善ができます.


// @_benac
//@version=5
strategy('Larry', overlay=true , initial_capital=1000 )


////////////////////////////////////////////////////////
//                                                    //
//                                                    //
//                 Codigo Operacional                 //
//                                                    //
//                                                    //
////////////////////////////////////////////////////////

// Usage for Stocks , or Criptos with value bigger then 1, cuz of 0.01 ´pip.
// Daily timeframe
//Observation Point
start     = timestamp(2020, 00, 00, 00, 00)         // backtest start window
finish    = timestamp(2022, 01, 07, 23, 59)        // backtest finish window
window()  => true // create function "within window of time"  

if time < start 
    strategy.close_all("Closing All")

// Take infos from inputs. 
inp_mmshort = input.int(defval = 9, title = "Media Curta"  )
inp_mminter = input.int(defval = 21, title = "Media Curta"  )

// Risk Manager, here define max and min 
inp_max = input.int(defval = 15, title = "Percentual Ganho"  )
inp_min = input.int(defval = 5, title = "Percental  Perda"  )

// Converting the input to % 
pmax = (inp_max / 100 )
pmin =  (inp_min / 100)

// Infos From Moving Average
mm_short = ta.sma(close , inp_mmshort)
mm_inter = ta.ema(close , inp_mminter)


// Trend Logic
//Long Condition 

//Setup do Larry Willians Bem Simples , media virou para cima e rompeu a maxima de referencia, compra. 
tendencia_alta = mm_short[2] > mm_short[1] and mm_short > mm_short[1] and close > high[1] and close > mm_short and mm_short > mm_inter
tendencia_baixa = mm_short[2] < mm_short[1] and mm_short < mm_short[1] and close > low[1] and close < mm_short and mm_short < mm_inter

// Creating the entry
if tendencia_alta 
    strategy.entry("Compra" , strategy.long , stop = low - 0.01  )
    stop_inst = low - 0.01 
if tendencia_baixa 
    strategy.entry("Venda" , strategy.short , stop= high + 0.01  )
    stop_inst = high + 0.01


// TrailingStop Creation

// Sell Position
if strategy.position_size < 0 
    gain_p = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * pmax) 
    stop_p = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * pmin) 
    // Managing the position
    if close < gain_p 
        strategy.close_all(comment = " 1 - Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
    if close > stop_p 
        strategy.close_all(comment = " 2 - Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
    
    if  high > mm_short[1]
        strategy.close_all(comment = " 3 - Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
      

// Buy Position    
if strategy.position_size > 0
    gain_p = strategy.opentrades.entry_price(0) + (strategy.opentrades.entry_price(0) * pmax) 
    stop_p = strategy.opentrades.entry_price(0) - (strategy.opentrades.entry_price(0) * pmin) 
    // Managing the position
    if close > gain_p 
        strategy.close_all(comment = " 1- Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
    if close < stop_p 
        strategy.close_all(comment = " 2 -Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
    if low < mm_short[1]
        strategy.close_all(comment = " 3 -Ganho : " + str.tostring( gain_p) + " Perda : " + str.tostring( stop_p)  )
        



もっと