ゴールデンクロス強気トレンドフォロー戦略


作成日: 2024-01-03 11:46:44 最終変更日: 2024-01-03 11:46:44
コピー: 1 クリック数: 567
1
フォロー
1621
フォロワー

ゴールデンクロス強気トレンドフォロー戦略

概要

この戦略は,移動平均の黄金十字原理に基づいて設計されている.具体的には,それは50周期線と200周期線という2つの異なる周期の単純な移動平均を使用している.50周期線が下から200周期線を突破すると,買入シグナルが生成され,50周期線が上から200周期線を突破すると,売り込みシグナルが生成される.

戦略原則

この策略は,Pine Script言語で記述されており,主な論理は以下の通りです.

  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. 安定版のPine言語で記述され,効率的に動作します.
  4. 視覚設定は情報に富み,使いやすい.

リスクと解決

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

  1. 偽突破が発生し,策略が誤信号を生成する可能性がある.二つの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, "#.##"))