STOCH取引戦略に基づく自動取引


作成日: 2023-09-28 11:38:44 最終変更日: 2023-09-28 11:38:44
コピー: 0 クリック数: 705
1
フォロー
1621
フォロワー

この戦略は,STOCH指標をベースにシンプルな自動取引システムを設計した. この戦略は,外貨,株式指数,大宗商品などの市場に適しており,株式市場や暗号通貨市場にも拡張できます.

戦略概要

この戦略は,STOCH指標を使用して,超買い超売り状態を識別し,PIVOT点と組み合わせて,ストップ・ロスの位置を設定し,トレンドを追跡します.STOCH指標が超買い超売りを示しているときに,多額の空白操作を行います.ストップ・ロスは,当日のPIVOT点の近くに設置され,リスクを効果的に制御できます.部分的なストップ・ポイントは,一定の利益の後,部分的なポジションを閉鎖します.

戦略原則

この戦略は,STOCH指標の快線%Kと慢線%Dを使用して金叉の多行と死叉の空行を実現する.具体的ロジックは,%K線が下から上へ%D線を突破すると,多行操作を行うこと;%K線が上から下へ%D線を突破すると,空行操作を行うこと.このように,超買超売状態を捕捉することができる.

リスクを制御するために,長ポジションは,その日の最低のPIVOT点の近くで多損失のストップポイントを設定し,空ポジションは,その日の最高のPIVOT点の近くで空損失のストップポイントを設定し,リスクを効果的にロックすることができます.

部分的なストップ・ストップの論理は,開設後に特定の利益水準で50%のポジションを閉鎖することである.これにより,資金使用効率を最適化することができる.

全体として,この戦略は,Captureが過買過売状態のちょうどその時点;Controlのリスク管理の側面;Optimizeの資金使用効率.Capture,ControlとOptimizeの有機的な組み合わせと言える.

戦略的優位性

  • STOCH指標を使用すると,過剰買いや過剰販売の現象を効果的に捉えることができ,PIVOTポイントでリスクを制御でき,取引リスクを完全にコントロールできます.

  • 部分停止メカニズムは,資金使用効率を最適化します.部分平仓の方法を採用し,部分利益を確保するとともに,後の稼働の利潤スペースを保持します.

  • 戦略のパラメータはカスタマイズ可能で,トレーダーは市場とリスクの好みに応じてパラメータを調整して,戦略の柔軟な使用を実現します.

  • 策略論理は,非常にシンプルで明快で,容易に理解し,異なるトレーダーが使用するのに適しています.コードは直感的に読みやすく,変更し,維持するのに便利です.

戦略リスク

  • トレンドフォローの戦略として,変動の状況に巻き込まれ,利益を得られない.

  • STOCH指標は誤った信号を生じ,不必要な取引行動を誘発する可能性がある.無意味な取引を避けるために,適切な信号をフィルターする必要があります.

  • ストップポイントは当日の枢軸点に近いので,突破した後に近すぎる可能性があるので,適切なストップ距離を拡大すべきである.

  • 期間長さなどの一部の戦略パラメータは,異なる市場に応じて調整する必要がある.そうでなければ,戦略のパフォーマンスに影響を与えるだろう.

  • 追憶は過去のデータのみで,将来のパフォーマンスを保証することはできません. リアルディスクは,制御不能な要因により影響を受けます.

  • 自動取引システムは,サーバーの安定性を確保し,接続上の問題により正常な取引ができないことを避ける必要があります.

戦略最適化の方向性

  • トレンドフィルタを導入し,トレンドが不明の時に盲目取引を避ける.例えば,トレンドの方向を判断するMA指数を加える.

  • 取引量モニタリング,放量,空頭放量など,偽突破をフィルタリングする.

  • 異なる品種,周期に応じてパラメータを調整して,戦略のパフォーマンスを最適化できます.例えば,STOCHのパラメータを調整します.

  • 機械学習アルゴリズムを組み込み,ビッグデータ訓練モデルを利用し,パラメータを自動的に最適化することも検討できる.

  • リスクコントロールを導入するために,損失比を設定し,大きな損失が発生しないようにします.

  • 追加条件は,入場タイミングをフィルタリングし,戦略の勝率を向上させるためのものです.例えば,株式の基本的モデルを導入するなどです.

要約する

この戦略は,全体として,単純で直観的なトレンド追跡方法を採用し,STOCH指標で超買い超売り状態を識別し,PIVOTの止損を加え,リスクを制御し,資金効率を最適化するために部分的な止まりを導入します.Capture,Control,Optimizeの3つのレベルから設計され,より完全な自動取引システムを形成します.この戦略の論理は,簡単に理解でき,パラメータはカスタマイズでき,異なるトレーダーに使用できます.しかし,一定のリスクと欠陥があり,現場で継続的にテストされ,最適化され,長期的に安定した利益を生む必要があります.

ストラテジーソースコード
/*backtest
start: 2022-09-21 00:00:00
end: 2023-09-27 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Peter_O

//@version=4
// strategy(title="TradingView Alerts to MT4 MT5 - Forex, indices, commodities, stocks, crypto", commission_type=strategy.commission.cash_per_contract, commission_value=0.00003, overlay=false, default_qty_value=20000, initial_capital=1000)
//
// This script was created for educational purposes only.
// It is showing how to use Alerts-Straight-From-Strategies and
// dynamic variables in TradingView alerts.
// And how to auto-execute them in Forex, indices, commodities markets
// 
// (This method will also work with stocks and crypto - anything your 
// broker is offering via their MT4/MT5 platform).
 
TakeProfitLevel=input(400)
TakePartialProfitLevel=input(150)

// **** Entries logic **** {
periodK = input(13, title="K", minval=1)
periodD = input(3, title="D", minval=1)
smoothK = input(4, title="Smooth", minval=1)
k = sma(stoch(close, high, low, periodK), smoothK)
d = sma(k, periodD)
plot(k, title="%K", color=color.blue)
plot(d, title="%D", color=color.orange)
h0 = hline(80)
h1 = hline(20)
fill(h0, h1, color=color.purple, transp=75)

GoLong=crossover(k,d) and k<80 and year>2009
GoShort=crossunder(k,d) and k>20 and year>2009

AlertTest=open>close or open<close or open==close
// } End of entries logic

// **** Pivot-points and stop-loss logic **** {
piv_high = pivothigh(high,1,1)
piv_low = pivotlow(low,1,1)
var float stoploss_long=low
var float stoploss_short=high

pl=valuewhen(piv_low,piv_low,0)
ph=valuewhen(piv_high,piv_high,0)

if GoLong 
    stoploss_long := low<pl ? low : pl
if GoShort 
    stoploss_short := high>ph ? high : ph
// } End of Pivot-points and stop-loss logic

// **** Trade counter and partial closing mechanism **** {
var int trade_id=0
if GoLong or GoShort
    trade_id:=trade_id+1

TakePartialProfitLong = barssince(GoLong)<barssince(GoShort) and crossover(high,(valuewhen(GoLong,close,0)+TakePartialProfitLevel*syminfo.mintick))
TakePartialProfitShort = barssince(GoLong)>barssince(GoShort) and crossunder(low,(valuewhen(GoShort,close,0)-TakePartialProfitLevel*syminfo.mintick))
// } End of Trade counter and partial closing mechanism

strategy.entry("Long", strategy.long, when=GoLong)
strategy.exit("XPartLong", from_entry="Long", qty_percent=50, profit=TakePartialProfitLevel)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.entry("Short", strategy.short, when=GoShort)
strategy.exit("XPartShort", from_entry="Short", qty_percent=50, profit=TakePartialProfitLevel)
strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)

if GoLong
    alertsyntax_golong='long slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if GoShort
    alertsyntax_goshort='short slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id) + ' tp=' + tostring(TakeProfitLevel)
    alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)
if TakePartialProfitLong
    alertsyntax_closepartlong='closepart tradeid=' + tostring(trade_id) + ' part=0.5'
    alert(message=alertsyntax_closepartlong, freq=alert.freq_once_per_bar_close)
if TakePartialProfitShort
    alertsyntax_closepartshort='closepart tradeid=' + tostring(trade_id) + ' part=0.5'
    alert(message=alertsyntax_closepartshort, freq=alert.freq_once_per_bar_close)