
この戦略は,有名なトレーダーであるラリー・ウィリアムズが作成したシンプルで古典的な移動平均を横断する戦略である. 9日のシンプル移動平均を快線として,21日のインデックス移動平均を慢線として使用する. 価格が上昇すると9日線を突破し,価格が下がると9日線を突破すると空にする. 偽の突破をフィルターするために,21日線補助判断傾向も導入する.
この戦略は,移動平均線の黄金交差と死交差に基づいて,プラスとマイナスの機会を判断する. 快線が,下からゆっくりとした線を横切るときに,金に交差し,市場がブルッシュであることを示すような突破を行う. 快線が,上からゆっくりとした線を横切るときに,死交差し,市場がベアであることを示すような突破を行う.
虚偽の突破が仮想の損失をもたらすのを防ぐために,戦略は21日線を判断する大傾向も導入した. 取引行動は,快線の突破と同時に,価格が21日線を突破したときにのみ行われます.
具体的には,多行信号は:快線上が昨日の高点を突破し,同時に快線が21日線を突破するので,多頭が成立する.空行信号は:快線下落が昨日の低点を突破し,同時に快線が21日線を突破するので,空頭が成立する.
この戦略の利点は以下の通りです.
この戦略には以下のリスクがあります.
上記のリスクは,以下の方法で最適化および制御できます.
この戦略は以下の方向から最適化できます.
パラメータ最適化.より体系的な方法でMA周期パラメータの組み合わせをテストして,より優良なパラメータを見つけることができる.
損失を増やす. 合理的な移動損失,縮小損失などの方法を設定し,単一の損失を効果的に制御する.
他の指標と組み合わせる.MACD,ATR,KDなどの他の指標信号を導入し,より多くの次元で確認し,戦略の安定性を高める.
出場メカニズムの最適化 異なるタイプの出場戦略,例えば反転信号出場,移動止止出場などの方法の研究
移動平均を横断する戦略は,全体として非常に典型的で実用的なトレンド追跡戦略である.それは理解しやすく実行する利点があり,いくつかの改善の余地もあります.パラメータ最適化,ストップスロース最適化,多指標結合などの方法によって,この戦略を継続的に改善して,より安定した実用的な取引システムにすることができます.
// @_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) )