ダイナミックストップ・ロース・アラート トレーディングView 戦略

作者: リン・ハーンチャオチャン, 日付: 2023-09-18 17:20:06
タグ:

概要

この戦略は,TradingConnectorを使用してMT4/5プラットフォームで実行するためのTradingViewアラートを通じてダイナミックストップロスの価格を通過することを示します.エントリは,最近のピボットに設定されたダイナミックストップでストカスティック指標を使用して決定されます.部分的な利益を取ることも可能です.

戦略の論理

ストキャストKとD線の交差点における長距離と短距離エントリ.最近のピボット高値/低値は動的ストップ損失価格として計算される.これらはエントリー時のアラートを通じてリアルタイムでブローカーに送信される.部分的な利益はストップ損失距離の特定のパーセントで取られる.利益価格は動的にアラートすることもできる.

利点

  • ダイナミックストップは,手術によるストップ損失の配置を可能にします.
  • 部分的な利益は資本効率を向上させる
  • ストップ・ロスの価格をブローカー口座にリアルタイムで転送する
  • バックテストされたストップ・ロスは ライブでリアルなシミュレーションを模倣します

リスク

  • ストカスティック指標の遅延がある
  • 頻繁に部分利益を引き出すこと
  • ダイナミック変数は 異なる時間枠で異なる振る舞いをします
  • 部分利益率は最適化が必要

ストカスト的パラメータを調整し 部分利益率を調整することで リスクを管理できます

改良

  • 異なるストカスティックパラメータの組み合わせをテストする
  • 部分利益率を最適化する
  • トレイリングストップのような他のストップ・ロスのアプローチを探ります.
  • 市場や製品にわたる信頼性をテストする

結論

この戦略は,新しい機能を使用してTradingViewからMT4/5へのダイナミックストップロスの取引を実行することを実証しています.さらなるバックテストのための枠組みとして機能できます.特定の資産のために最適化が必要です.


/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4
// strategy(title="TradingView Alerts to MT4 MT5 Strategy example", commission_type=strategy.commission.cash_per_order, commission_value=0.00003, overlay=false, default_qty_value=100000, initial_capital=1000)
// study(title="TradingView Alerts to MT4 MT5 Strategy example")  //uncomment this line and comment previous one to make it a study producing alerts
//
// This script was created for educational purposes only.
// It is showing how to use dynamic variables in TradingView alerts.
// And how to execute them in Forex, indices and commodities markets
// thanks to www.tradingconnector.com

TakeProfitLevel=input(400)
TakePartialProfitLevel=input(150)

// **** Entries logic **** {
periodK = input(14, 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
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
// } 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]+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)


// alertcondition("Long", when=GoLong, message="long slprice={{stoploss_long}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("Short", when=GoShort, message="short slprice={{stoploss_short}} tradeid={{trade_id}} tp=TakeProfitLevel")
// alertcondition("ClosePartLong", when=TakePartialProfitLong, message="closepart tradeit={{trade_id}} part=0.5")
// alertcondition("ClosePartShort", when=TakePartialProfitShort, message="closepart tradeit={{trade_id}} part=0.5")


もっと