オープン 閉じる クロス 移動平均 トレンド ストラテジーをフォロー

作者: リン・ハーンチャオチャン,日付: 2024-01-15 14:24:27
タグ:

img

概要

オープン・クローズ・クロス・ムービング・平均トレンドフォロー戦略 (Open Close Cross Moving Average Trend Following Strategy) は,オープン・クローズ価格の移動平均値に基づいたトレンドフォロー戦略である.オープン・クローズ価格の移動平均値を計算することによって,現在の市場トレンドを決定する.閉店価格移動平均値がオープニング価格移動平均値を超えるとロングになり,閉店価格移動平均値がオープニング価格移動平均値を下回るとショートとなる.この戦略は,利益を固定し,リスクを効果的に制御するためにトラッキングストップを設定する.

原則

この戦略の基本論理は,現在のトレンドを決定するためのオープンと閉鎖価格の関係に基づいている.開口価格は現在の市場需要供給関係と取引心理学を反映し,閉じる価格は日の最終取引結果を反映する.一般的に,閉じる価格がオープニング価格よりも高くなった場合,その日の市場のトレンドが上昇し,センチメントが上昇していることを示唆する.閉じる価格がオープニング価格より低い場合,その日の市場のトレンドが下落し,センチメントが上昇していることを示唆する.

この戦略は,現在のトレンド方向を判断するために,開閉価格の移動平均を計算することによって,この論理を利用する.具体的には,取引規則は以下のとおりである.

  1. 閉店価格移動平均が開店価格移動平均を上回るとロングする.これは上昇傾向が強くなっていることを示し,ロングポジションを開始することができます.

  2. 閉店価格移動平均が開店価格移動平均を下回るとショートします.これは下落傾向が上昇していることを示し,ショートポジションを開始することができます.

  3. 逆信号が来ると,ストップ損失で既存のポジションを閉じる.

ストラテジーは,収益をロックするためにトライリングストップも設定する.ポジションに入ると,エントリー価格と現在の価格との間のポイント差を動的に計算する.価格動きが設定されたストップ損失ポイントの値を超えると,ストップ損失線は部分的な利益をロックするために上昇する.

要するに,この戦略は移動平均期間の長さの傾向を判断し,一度に1つの方向的なポジションのみを保持し,ATRストップなしで逆信号で既存のポジションを直接終了し,利益をロックするためのトライリングストップ設定を持っています.

利点分析

この戦略には以下の主な利点があります.

  1. シンプル で 明確 な ルールオープン・クローズ関係に基づく傾向を判断することは,パラメータを理解し最適化することが容易です.

  2. 柔軟なMA選択選択し最適化できる マジカル・メカニズムの種類は数十種類あります

  3. 調整可能な解像度信号の感度とタイミングを高めるため,解像度はチャートの3~4倍に設定できます.

  4. 損失を停止するメカニズムトレーリングストップは,取引ごとに損失と引き下げを効果的に制御します.

  5. 調整可能な保管期間保持期間と変動は,MAパラメータを調整することによって制御できます.

  6. 柔軟に調整できるリスク報酬ストップ・ロストポイントとオフセット リスク・リターン偏好

リスク分析

この戦略の主なリスクは次の分野にあります

  1. 欠落 し て いる 傾向 の 逆転エクジットシグナルは価格逆転に遅れ,損失を伴う可能性があります.MA期間を短縮することでこれを軽減できます.

  2. 高波動性条件には適さない変動条件下での頻繁なウィップソーでは高額な手数料がかかります.ストップ・ロスのポイントを広げたり,MA期間を延長したりすることで,この問題解決に役立ちます.

  3. 単一指標への依存. たった1つの指標セットに基づく決定は,失敗リスクにさらします. MACDのような他の指標を追加すれば,論理を補完できます.

  4. 過剰な最適化リスク. MAパラメータとストップ損失設定は簡単にオーバーフィットされる可能性があります. サンプル外でのパフォーマンスが悪化する可能性があります. パラメータ選択には注意が必要です.

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

戦略は以下のような分野から最適化・強化できます.

  1. 補完指標不安定性と動力指標は強度と安定性を高めます

  2. 条件動的パラメータ市場調節期間は,傾向や横向的な市場レジムの検出に基づいて調整され,適応性が向上します.

  3. ダイナミックリスク管理ストップ・ロスト・ポイントとオフセットは,最近実現した変動レベルで校正できます.

  4. ストップ・ロスのロジックが強化されたATRストップのようなより高度なストップ・ロスのメカニズムは シンプルなトレーリング・ストップを 置き換えることができます

結論

オープン・クローズ・クロス・ムービング・平均トレンドフォロー戦略 (Open Close Cross Moving Average Trend Following Strategy) は,オープン・クローズ・関係とムービング・平均値に基づいた典型的なトレンド・トレード戦略である. シンプルなルール,柔軟性,制御可能なリスクなどの利点は,見逃した逆転やウィップソーなどの欠点も伴っている. 強化分野には,より多くの指標,ダイナミックパラメータ,より優れたトレンドキャッチと変動する市場状況への適応性のための高度なリスク管理が含まれている.


/*backtest
start: 2023-01-08 00:00:00
end: 2024-01-14 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

strategy(title = "Open Close Cross Strategy (PineScript=v4)", shorttitle = "OCC Strategy", overlay = true )

// Revision:        1
// Author:          @JayRogers
//
// Description:
//  - Strategy based around Open-Close Crossovers.
// Setup:
//  - I have generally found that setting the strategy resolution to 3-4x that of the chart you are viewing
//    tends to yield the best results, regardless of which MA option you may choose (if any)
//  - Don't aim for perfection. Just aim to get a reasonably snug fit with the O-C band, with good runs of
//    green and red.
//  - Option to either use basic open and close series data, or pick your poison with a wide array of MA types.
//  - Optional trailing stop for damage mitigation if desired (can be toggled on/off)
//  - Positions get taken automagically following a crossover - which is why it's better to set the resolution
//    of the script greater than that of your chart, so that the trades get taken sooner rather than later.
//  - If you make use of the trailing stops, be sure to take your time tweaking the values. Cutting it too fine
//    will cost you profits but keep you safer, while letting them loose could lead to more drawdown than you
//    can handle.

// === INPUTS ===
useRes = input(defval=true, title="Use Alternate Resolution? ( recommended )")
stratRes = input(defval="120", title="Set Resolution ( should not be lower than chart )", type=input.resolution)
useMA = input(defval=true, title="Use MA? ( otherwise use simple Open/Close data )")
basisType = input(defval="DEMA", title="MA Type: SMA, EMA, DEMA, TEMA, WMA, VWMA, SMMA, HullMA, LSMA, ALMA ( case sensitive )", type=input.string)
basisLen = input(defval=14, title="MA Period", minval=1)
offsetSigma = input(defval=6, title="Offset for LSMA / Sigma for ALMA", minval=0)
offsetALMA = input(defval=0.85, title="Offset for ALMA", minval=0, step=0.01)
useStop = input(defval=true, title="Use Trailing Stop?")
slPoints = input(defval=200, title="Stop Loss Trail Points", minval=1)
slOffset = input(defval=400, title="Stop Loss Trail Offset", minval=1)
// === /INPUTS ===

// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
    v1 = sma(src, len)  // Simple
    v2 = ema(src, len)  // Exponential
    v3 = 2 * v2 - ema(v2, len)  // Double Exponential
    v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len)  // Triple Exponential
    v5 = wma(src, len)  // Weighted
    v6 = vwma(src, len)  // Volume Weighted
    sma_1 = sma(src, len)  // Smoothed
    v7 = na(v5[1]) ? sma_1 : (v5[1] * (len - 1) + src) / len
    v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len)))  // Hull
    v9 = linreg(src, len, offSig)  // Least Squares
    v10 = alma(src, len, offALMA, offSig)  // Arnaud Legoux
    type == "EMA" ? v2 : type == "DEMA" ? v3 : type == "TEMA" ? v4 : 
       type == "WMA" ? v5 : type == "VWMA" ? v6 : type == "SMMA" ? v7 : 
       type == "HullMA" ? v8 : type == "LSMA" ? v9 : type == "ALMA" ? v10 : v1
// security wrapper for repeat calls
reso(exp, use, res) =>
    security_1 = security(syminfo.tickerid, res, exp)
    use ? security_1 : exp
// === /BASE FUNCTIONS ===

// === SERIES SETUP ===
// open/close
variant__1 = variant(basisType, close, basisLen, offsetSigma, offsetALMA)
reso__1 = reso(variant__1, useRes, stratRes)
reso__2 = reso(close, useRes, stratRes)
closeSeries = useMA ? reso__1 : reso__2
variant__2 = variant(basisType, open, basisLen, offsetSigma, offsetALMA)
reso__3 = reso(variant__2, useRes, stratRes)
reso__4 = reso(open, useRes, stratRes)
openSeries = useMA ? reso__3 : reso__4
trendState = bool(na)
trendState := closeSeries > openSeries ? true : 
   closeSeries < openSeries ? false : trendState[1]
// === /SERIES ===

// === PLOTTING ===
barcolor(color=closeSeries > openSeries ? #006600 : #990000, title="Bar Colours")
// channel outline
closePlot = plot(closeSeries, title="Close Line", color=#009900, linewidth=2, style=plot.style_line, transp=90)
openPlot = plot(openSeries, title="Open Line", color=#CC0000, linewidth=2, style=plot.style_line, transp=90)
// channel fill
closePlotU = plot(trendState ? closeSeries : na, transp=100, editable=false)
openPlotU = plot(trendState ? openSeries : na, transp=100, editable=false)
closePlotD = plot(trendState ? na : closeSeries, transp=100, editable=false)
openPlotD = plot(trendState ? na : openSeries, transp=100, editable=false)
fill(openPlotU, closePlotU, title="Up Trend Fill", color=#009900, transp=40)
fill(openPlotD, closePlotD, title="Down Trend Fill", color=#CC0000, transp=40)
// === /PLOTTING ===

// === STRATEGY ===
// conditions
longCond = crossover(closeSeries, openSeries)
shortCond = crossunder(closeSeries, openSeries)
// entries and base exit
strategy.entry("long", strategy.long, when=longCond)
strategy.entry("short", strategy.short, when=shortCond)
// if we're using the trailing stop
if useStop
    strategy.exit("XL", from_entry="long", trail_points=slPoints, trail_offset=slOffset)
    strategy.exit("XS", from_entry="short", trail_points=slPoints, trail_offset=slOffset)
// not sure needed, but just incase..
strategy.exit("XL", from_entry="long", when=shortCond)
strategy.exit("XS", from_entry="short", when=longCond)
// === /STRATEGY ===


もっと