
この記事では,ラリー・ウィリアムズ三周期動平均線に基づく取引戦略について説明します. この戦略は,価格の傾向を捉えるために,2つの指数移動平均 ((EMA) を利用し,K線の3つの連続した閉盘価格がEMAを破るときに取引信号を生成します. 戦略のパラメータは,異なる市場と周期に適用して調整できます.
ラリー・ウィリアムズ三周期動的均等線取引戦略は,双EMAと連続したK線方向に基づくトレンド追跡戦略で,パラメータ最適化により異なる市場に対応できる.しかし,戦略自体は比較的シンプルで,震動市場では不良なパフォーマンスであり,風力管理の対策が欠如しており,さらなる最適化と改善が必要である.戦略の優劣を総合的に考慮すると,戦略は,トレンドが明快な市場で使用するのに適しており,ポジション管理とリスク管理の措置を配合して,全体的なパフォーマンスと安定性を向上させる.
/*backtest
start: 2023-05-05 00:00:00
end: 2024-05-10 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Larry Williams 3 Periodos Editável de MarcosJr", overlay=true, process_orders_on_close=true)
// Parametrização do período do EMA
emaPeriodHighs = input.int(title="Highs Period", defval=3, minval=1, maxval=9999)
emaPeriodLows = input.int(title="Lows Period", defval=3, minval=1, maxval=9999)
// Parametrização da data de início e fim do período a ser coletado
startYear = input.int(title="Start Year", defval=2020)
startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)
startDay = input.int(title="Start Day", defval=1, minval=1, maxval=31)
endYear = input.int(title="End Year", defval=2020)
endMonth = input.int(title="End Month", defval=12, minval=1, maxval=12)
endDay = input.int(title="End Day", defval=31, minval=1, maxval=31)
// Convertendo data de início e fim para timestamp
startDate = timestamp(startYear, startMonth, startDay, 00, 00)
endDate = timestamp(endYear, endMonth, endDay, 23, 59)
// EMA
emaH = ta.ema(high, emaPeriodHighs)
emaL = ta.ema(low, emaPeriodLows)
// PLOT:
// Desenha as linhas EMA no gráfico
plot(emaH, color=color.green, linewidth=2)
plot(emaL, color=color.red, linewidth=2)
// Condições
inDateRange = true
// Verifica se houve mais de três candles consecutivos do mesmo sentido
checkThreeConsecutiveCandles = (close[0] > close[1] and close[1] > close[2] and close[2] > close[3]) or (close[0] < close[1] and close[1] < close[2] and close[2] < close[3])
if(close < emaL and inDateRange and checkThreeConsecutiveCandles and barstate.isconfirmed)
strategy.entry("Long", strategy.long, comment="Long", when=strategy.position_size == 0)
if(close > emaH and inDateRange and checkThreeConsecutiveCandles and barstate.isconfirmed)
strategy.close("Long", comment="Close Long")
// Fechar a operação no fechamento do pregão
if(strategy.position_size > 0 and na(time_close[0]))
strategy.close("Long", comment="Close Long")