トリプル・ムービング・メアディア・トレンド 戦略をフォロー

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

img

概要

この戦略は,トートル取引の概念とニコ・ベイカーズ・フェーズ分析を組み合わせ,トレンドをたどるトレンド方向を決定するために異なるサイクルの3つの移動平均を使用する.高速移動平均が中間移動平均を横切り,すべての3つの移動平均が同じ上昇または下落傾向にあるとき,長くなります.高速移動平均が中間移動平均を下回り,すべての3つの移動平均が同じ上昇または下落傾向にあるとき,短くなります.

戦略の論理

  1. 異なる周期の3つの移動平均を計算します. 急速移動平均期間は8日,中間移動平均期間は21日,ゆっくり移動平均期間は55日です.

  2. 入場条件を決定する. 急速移動平均が平均移動平均を上回り,すべての3つの移動平均が上昇傾向にある場合,ロング; 急速移動平均が平均移動平均を下回り,すべての3つの移動平均が減少傾向にある場合,ショート.

  3. 出口条件を決定する: 快速移動平均が逆の方向で中間移動平均を横切ったとき,ポジションを閉じる.

  4. ポジションサイズ:固定ポジションサイズを使用し,毎回1つの契約を開きます.ATRはポジションサイズを動的に調整するためにも使用できます.

利点分析

  1. 3つの移動平均値を用いることで,トレンドの方向性を決定し,誤ったブレイクを避けるのに役立ちます.

  2. 利益の可能性について

  3. 移動平均を用いると 安定した利益と 比較的少ない引き上げが得られる.

  4. 制御可能なストップ・ロスの戦略は 巨大な損失の確率を減らすことができます

リスク分析

  1. 利益効率を低下させる

  2. 移動平均は遅れており,トレンド逆転点を見逃す可能性があります.

  3. 固定ポジションのサイジングはリスクを効果的にコントロールできず,市場変動の際には,マーージンコールを引き起こす可能性があります.

  4. パラメータの最適化が不適切であれば,過剰な取引が起こり,取引コストが増加し,スライプが起こります.

最適化

  1. 移動平均期間の最適化は,取引手段の特徴に合わせて行う.

  2. 動的に位置のサイズを調整するためにATRを使用します.

  3. ストップ・ロスト戦略を追加します

  4. 取引量の指標を組み込み,動向の信頼性を決定する.

概要

この戦略は,トレンドを追跡するために3つの移動平均値を使用して,伝統的な技術指標と亀取引の哲学を統合している.適切なパラメータ最適化により,良い収益性を達成することができる.しかし,いくつかのリスクも伴います.ストップ損失,ポジションサイズおよびその他の措置は,リスクを制御し,この定量的な取引戦略から長期にわたる安定した利益を得るために利用する必要があります.


/*backtest
start: 2024-01-01 00:00:00
end: 2024-01-31 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// LOVE JOY PEACE PATIENCE KINDNESS GOODNESS FAITHFULNESS GENTLENESS SELF-CONTROL 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © JoshuaMcGowan

//@version=4

// 1. Define strategy settings
strategy(title="Triple Moving Average", overlay=true,
     pyramiding=0, initial_capital=1000,
     commission_type=strategy.commission.cash_per_order,
     commission_value=4, slippage=2)
     
fastMALen = input(title="Fast MA Length", type=input.integer, defval=8)
medMALen  = input(title="Medium MA Length", type=input.integer, defval=21)
slowMALen = input(title="Slow MA Length", type=input.integer, defval=55)

//endMonth = input(title="End Month Backtest", type=input.integer, defval=11)
//endYear  = input(title="End Year Backtest", type=input.integer, defval=2019)

// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 12, title = "From Month", minval = 1, maxval = 12)
FromDay   = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear  = input(defval = 2016, title = "From Year", minval = 2017)
ToMonth   = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay     = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear    = input(defval = 9999, title = "To Year", minval = 2017)

// === FUNCTION EXAMPLE ===
start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)  // backtest start window
finish    = timestamp(ToYear, ToMonth, ToDay, 23, 59)        // backtest finish window
window()  => true

usePosSize = input(title="Use Position Sizing?", type=input.bool, defval=true)
riskPerc   = input(title="Risk %", type=input.float, defval=0.5, step=0.25)

// 2. Calculate strategy values
fastMA = sma(close, fastMALen)
medMA  = sma(close, medMALen)
slowMA = sma(close, slowMALen)

//Position Sizing
riskEquity  = (riskPerc / 100) * strategy.equity
atrCurrency = (atr(20) * syminfo.pointvalue)
posSize     = usePosSize ? floor(riskEquity / atrCurrency) : 1

//Backtest Window
//tradeWindow = (time <= timestamp(endYear, endMonth, 1, 0, 0))

// 3. Determine long trading conditions
enterLong = crossover(fastMA, medMA) and
     (fastMA > slowMA) and (medMA > slowMA) and
     window() 

exitLong = crossunder(fastMA, medMA)

// 4. Code short trading conditions
enterShort = crossunder(fastMA, medMA) and
     (fastMA < slowMA) and (medMA < slowMA) and
     window() 

exitShort = crossover(fastMA, medMA)

// 5. Output strategy data
plot(series=fastMA, color=color.green, title="Fast MA")
plot(series=medMA, color=color.purple, title="Medium MA")
plot(series=slowMA, color=color.red, title="Slow MA",
     linewidth=2)
     
bgColour =
     enterLong and (strategy.position_size < 1) ? color.green :
     enterShort and (strategy.position_size > -1) ? color.red :
     exitLong and (strategy.position_size > 0) ? color.lime :
     exitShort and (strategy.position_size < 0) ? color.orange :
     na

bgcolor(color=bgColour, transp=85)

// 6. Submit entry orders
if (enterLong)
    strategy.entry(id="EL", long=true, qty=1)

if (enterShort)
    strategy.entry(id="ES", long=false, qty=1)

// 7. Submit exit orders
strategy.close_all(when=exitLong and
     (strategy.position_size > 0))
strategy.close_all(when=exitShort and
     (strategy.position_size < 0))

strategy.close_all(when=not window())

//END

もっと