ゴールデンクロス 上昇傾向追跡戦略

作者: リン・ハーンチャオチャン,日付: 2024-01-03 11時46分44秒
タグ:

img

概要

この戦略は,移動平均のゴールデンクロス原理に基づいて設計されています.具体的には,異なる期間の2つの単純な移動平均を使用します.すなわち50期線と200期線です.50期線が下から200期線を突破すると,購入信号が生成されます.50期線が上から200期線を突破すると,販売信号が生成されます.

戦略の論理

戦略はパインスクリプトで書かれています. 主な論理は以下の通りです.

  1. 2つのSMAを計算する.50期SMAと200期SMA.
  2. 黄金線を定義します. 50 期間の SMA が 200 期間の SMA を越えると,ロング
  3. 切符が切れている場合,50期間のSMAが200期間のSMAを下回る場合,閉じる

ここでSMAインジケーターを使用することの重要性は,市場の騒音を効果的にフィルタリングし,長期的トレンドを把握できるということです.高速なSMAラインが遅いSMAラインを越えてくると,短期上向きの勢力が長期下向きを倒し,買い信号を生成することを示します.

利点

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

  1. シンプルで分かりやすい原則で 実行も簡単です
  2. 合理的な PARAMETERS 設定, 2 つの SMA 期間をカスタマイズし,異なる市場に適応できます.
  3. パイン言語で安定したバージョンで書かれていて,効率的に動作します.
  4. 豊かな視覚設定で使いやすい

リスク と 解決策

この戦略にはいくつかのリスクもあります:

  1. 誤ったブレイクが発生し,誤った信号を生成します.誤ったブレイクの可能性を減らすために2つのSMAパラメータを調整できます.

  2. 短期市場には対応できない.長期投資者だけに適している.迅速なSMA期間を適切に短縮できる.

  3. ストップ・ロスを設定したり ポジション管理を適切に調整したりできます

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

この戦略は,次の側面でさらに最適化できます.

  1. フィルタリングのための他の指標を追加し,複数の購入/販売条件を組み合わせて誤った信号を減らす.

  2. ストップ・ロスのメカニズムを追加します.価格が特定のレベルを突破したとき,強制的なストップ・ロスはあります.

  3. ポジション管理を最適化します.トレンドに沿ってピラミッド,ストップ損失を追うなど. 引き下げを制御し,より高い収益を追求します.

  4. パラメータ最適化 異なるパラメータがリターン/リスク比に与える影響を評価する

結論

一般的には,これは典型的なトレンド追跡戦略である. SMAの優位性を利用して,単純かつ効率的に長期トレンドを把握する. スタイルのスタイルとチューニングスペースに基づいてカスタマイズすることができます. さらに最適化と改善のために既存の欠陥も注意する必要があります.


/*backtest
start: 2023-12-26 00:00:00
end: 2024-01-02 00:00:00
period: 30m
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// @version=4
//
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// www.tradingview.com/u/TradeFab/
// www.tradefab.com
// ___  __        __   __  __       __
//  |  |__)  /\  |  \ |__ |__  /\  |__)
//  |  |  \ /~~\ |__/ |__ |   /~~\ |__)
//
// DISCLAIMER: Futures, stocks and options trading involves substantial risk of loss 
// and is not suitable for every investor. You are responsible for all the risks and 
// financial resources you use and for the chosen trading system.
// Past performance is not indicative for future results. In making an investment decision,
// traders must rely on their own examination of the entity making the trading decisions!
//
// TradeFab's Golden Cross Strategy.
// The strategy goes long when the faster SMA 50 (the simple moving average of the last 50 bars) crosses
// above the SMA 200. Orders are closed when the SMA 50 crosses below SMA 200. The strategy does not short.
//
VERSION = "1.2"
// 1.2 FB 2020-02-09 converted to Pine version 4
// 1.1 FB 2017-01-15 added short trading
// 1.0 FB 2017-01-13 basic version using SMAs
//
strategy(
   title        = "TFs Golden Cross " + VERSION, 
   shorttitle   = "TFs Golden Cross " + VERSION, 
   overlay      = true
   )


///////////////////////////////////////////////////////////
// === INPUTS ===
///////////////////////////////////////////////////////////
inFastSmaPeriod     = input(title="Fast SMA Period", type=input.integer, defval=50, minval=1)
inSlowSmaPeriod     = input(title="Slow SMA Period", type=input.integer, defval=200, minval=1)

// backtest period
testStartYear       = input(title="Backtest Start Year",    type=input.integer, defval=2019, minval=2000)
testStartMonth      = input(title="Backtest Start Month",   type=input.integer, defval=1, minval=1, maxval=12)
testStartDay        = input(title="Backtest Start Day",     type=input.integer, defval=1, minval=1, maxval=31)
testStopYear        = input(title="Backtest Stop Year",     type=input.integer, defval=2099, minval=2000)
testStopMonth       = input(title="Backtest Stop Month",    type=input.integer, defval=12, minval=1, maxval=12)
testStopDay         = input(title="Backtest Stop Day",      type=input.integer, defval=31, minval=1, maxval=31)


///////////////////////////////////////////////////////////
// === LOGIC ===
///////////////////////////////////////////////////////////
smaFast = sma(close, inFastSmaPeriod)
smaSlow = sma(close, inSlowSmaPeriod)

bullishCross = crossover (smaFast, smaSlow)
bearishCross = crossunder(smaFast, smaSlow)

// detect valid backtest period
isTestPeriod() => true


///////////////////////////////////////////////////////////
// === POSITION EXECUTION ===
///////////////////////////////////////////////////////////
strategy.entry("long",  strategy.long,  when=bullishCross)
strategy.entry("short", strategy.short, when=bearishCross)


///////////////////////////////////////////////////////////
// === PLOTTING ===
///////////////////////////////////////////////////////////
// background color
nopColor = color.new(color.gray, 50)
bgcolor(not isTestPeriod() ? nopColor : na)

bartrendcolor = 
   close > smaFast and 
   close > smaSlow and 
   change(smaSlow) > 0 
       ? color.green 
       : close < smaFast and 
         close < smaSlow and 
         change(smaSlow) < 0 
             ? color.red 
             : color.blue
barcolor(bartrendcolor)
plot(smaFast, color=change(smaFast) > 0 ? color.green : color.red, linewidth=2)
plot(smaSlow, color=change(smaSlow) > 0 ? color.green : color.red, linewidth=2)

// label
posColor = color.new(color.green, 75)
negColor = color.new(color.red, 75)
dftColor = color.new(color.blue, 75)
posProfit= (strategy.position_size != 0) ? (close * 100 / strategy.position_avg_price - 100) : 0.0
posDir   = (strategy.position_size  > 0) ? "long" : strategy.position_size < 0 ? "short" : "flat"
posCol   = (posProfit > 0) ? posColor : (posProfit < 0) ? negColor : dftColor

var label lb = na
label.delete(lb)
lb := label.new(bar_index, max(high, highest(5)[1]),
   color=posCol,
   text="Pos: "+ posDir +
      "\nPnL: "+tostring(posProfit, "#.##")+"%" +
      "\nClose: "+tostring(close, "#.##"))
  

もっと