この戦略は,ストキャスティックオシレータ指標に基づいて市場の超買い超売り状態を判断し,弾性停止原理と組み合わせて短期取引を行う.ストキャスティック指標の金叉時に多めにし,死叉時に空っぽにし,前期枢軸のベースで弾性停止を設定し,利益を保証しながらリスクを制御する.
ストキャスティック・オシレータの指標は%K線と%D線を含んでいる.%K線が下から上へ%D線を突破すると金叉信号として多し,%K線が上から下へ%D線を突破するとデッドフォーク信号として空し.本策は,ストキャスティック指標の金叉デッドフォーク信号に基づいて判断することである.
具体的には,ストキャスティック指数金フォークでは,%K線値が80以下 (未超買い) であれば,多額の取引を行う.ストキャスティック指数デッドフォークでは,%K線値が20以上 (未超売り) であれば,空売りを行う.
GoLong=crossover(k,d) and k<80
GoShort=crossunder(k,d) and k>20
この戦略は,前期の中枢点に基づいてストップ価格を設定する弾性ストップの方法を使用し,コードは以下のとおりです.
piv_high = pivothigh(high,1,1)
piv_low = pivotlow(low,1,1)
stoploss_long=valuewhen(piv_low,piv_low,0)
stoploss_short=valuewhen(piv_high,piv_high,0)
枢軸は重要なサポート抵抗を代表し,もし価格が枢軸を突破すると,ポジションを退出し,ストップ価格の弾性が枢軸の変化に追随する.
さらに,ストップ・プライスは,現在の期間の最低価格と最高価格を考慮して,次のコードで示されるストップ・ポジションをさらに最適化します.
if GoLong
stoploss_long := low<pl ? low : pl
if GoShort
stoploss_short := high>ph ? high : ph
ストキャスティック指数を使って,市場が超買い超売り状態であるかを判断し,高値と低値を追うのを避ける.
市場変化に応じてストップポジションを最適化できる柔軟なストップ原理を適用する.
ストップダウンの効果を高めるため,枢軸突破を組み合わせてストップダウンを実現する.
最安値の最大値を考慮して,ストップ・ロスを最適化して,ストップ・ロスをより正確にする.
ストキャスティック指数で誤信号が出る危険性
ストップ・ローンの破綻による損失拡大のリスク
取引頻度で取引費用が増加するリスク
Chandelier Exit,移動ストップ,振動ストップなどのストップ戦略の最適化
入場条件を最適化して,他の指標と組み合わせてストキャスティック指標の偽信号を避ける
モバイルストップ,振動ストップなどの最適化ストップ方式により,より高いストップ率を実現
単一リスクの管理のために,固定の単位数,固定の投資比率などの位置管理を追加します.
K,D 期数,平滑周期などの最適化パラメータを設定し,異なる市場向けにパラメータを調整する
本戦略は,ストキャスティック指標によって超買い超売り状態の入場を判断し,弾力的なストップ方式を使用してリスク管理を行う.この戦略は,追高殺低,ストップ効果などの優位性を有しているが,一定の偽信号リスクも存在する.将来,入場条件,ストップ戦略,ストップ方式,リスク管理などの最適化によって,この戦略をさらに完善することができる.
/*backtest
start: 2023-08-28 00:00:00
end: 2023-09-27 00:00:00
period: 2h
basePeriod: 15m
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 example with cancelling pending orders", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=true, default_qty_value=100000, initial_capital=1000)
// This script was created for educational purposes only.
// It is showing how to create pending orders and cancel them
// Together with syntax to send these events through TradingView alerts system
// All the way to brokers for execution
TakeProfitLevel=input(400)
// **** Entries logic **** {
periodK = 13 //input(13, title="K", minval=1)
periodD = 3 //input(3, title="D", minval=1)
smoothK = 4 //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
GoShort=crossunder(k,d) and k>20
// } 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
plot(stoploss_long, color=color.lime, title="stoploss_long")
plot(stoploss_short, color=color.red, title="stoploss_short")
// } End of Pivot-points and stop-loss logic
CancelLong=crossunder(low,stoploss_long) and strategy.position_size[1]<=0 and strategy.position_size<=0
CancelShort=crossover(high,stoploss_short) and strategy.position_size[1]>=0 and strategy.position_size>=0
entry_distance=input(10, title="Entry distance for stop orders")
plotshape(CancelLong ? stoploss_long[1]-10*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.gray, textcolor=color.white, text="cancel\nlong", size=size.tiny)
plotshape(CancelShort ? stoploss_short[1]+10*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.gray, textcolor=color.white, text="cancel\nshort", size=size.tiny)
strategy.entry("Long", strategy.long, when=GoLong, stop=close+entry_distance*syminfo.mintick)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.cancel("Long", when = CancelLong)
strategy.entry("Short", strategy.short, when=GoShort, stop=close-entry_distance*syminfo.mintick)
strategy.exit("XShort", from_entry="Short", stop=stoploss_short, profit=TakeProfitLevel)
strategy.cancel("Short", when = CancelShort)
if GoLong
alertsyntax_golong='long offset=' + tostring(entry_distance) + ' slprice=' + tostring(stoploss_long) + ' tp=' + tostring(TakeProfitLevel)
alert(message=alertsyntax_golong, freq=alert.freq_once_per_bar_close)
if GoShort
alertsyntax_goshort='short offset=' + tostring(-entry_distance) + ' slprice=' + tostring(stoploss_short) + ' tp=' + tostring(TakeProfitLevel)
alert(message=alertsyntax_goshort, freq=alert.freq_once_per_bar_close)
if CancelLong
alertsyntax_cancellong='cancel long'
alert(message=alertsyntax_cancellong, freq=alert.freq_once_per_bar_close)
if CancelShort
alertsyntax_cancelshort='cancel short'
alert(message=alertsyntax_cancelshort, freq=alert.freq_once_per_bar_close)