
この戦略は,Stoch指数を使用して入場シグナルを判断し,入場後,価格の新高または新低をリアルタイムで追跡し,ストープを動的に調整する.同時に,戦略は,アラート機能を使用して,ストープの修正情報をMT4/MT5に送信し,実際の取引中のポジションをリアルタイムで調整する.
この戦略は,ストック指数に基づく買入と売却のシグナルを生成し,ストックのKラインが下からDラインを突破すると買入シグナルを生成し,ストックのKラインが上から下からDラインを突破すると売りシグナルを生成する.
入場後,戦略は,最低価格の最新低点と最高価格の最新高点をリアルタイムで追跡し,ダイナミックなストップ・ロズとして使用する.具体的には,複数注文を行う場合,最低価格の最近低点をストップ・ロズとして追跡する.空調注文を行う場合,最高価格の最近高点をストップ・ロズとして追跡する.
ストップレスの変化が検出された場合,ストップレスを修正する指示をアラート機能で生成し,MT4/MT5にリアルタイムで実際の取引中のストップレスを調整するために送信します.同時に,ストップレスの変化を直視的に表示するためにグラフィックマークを描きます.
この戦略は,ダイナミック・ストップ・メカニズムが有効かどうかを手動で制御することをサポートする.有効にすると,市場の変動に応じてリアルタイムでストップ・トラッキング価格を調整することができる.
ダイナミック・トラッキング・ストップ・メカニズムを採用し,市場の波動に応じて柔軟にストップ・ポイントを調整し,ストップ・トラッキングを実現し,リスクを効果的に制御する.
警告機能を使用して,ストップ・ローズ調整情報をMT4/MT5にリアルタイムで送信し,人工の介入なしに自動管理を行うことができます.
止損調整情報をグラフィックで直感的に表示し,止損追跡の効果を簡単に閲覧および検証します.
ストップ・ロース・トラッキング機能の有効性を手動で制御し,異なる市場条件に柔軟に対応する.
ストック指標のタイミング判断と組み合わせると,偽突破を効果的にフィルターし,戦略の安定性を向上させることができる.
ストッチ指標は,頻繁に交差信号が発生し,より多くの無効操作のリスクを伴う. 適切なパラメータを調整して信号をフィルターすることができます.
極端な状況では,ストップロスが突破され,巨額の損失を完全に回避できないリスクがあります. 適切なタイミングでポジションのリスクを監視してください.
alert 接続に障害や遅延が発生し,リアルタイムでのフィードバックによる調整ができないため,誤り処理を行う必要があります.
ダイナミック・トラッキング・ストップ・ロスは,比較的密集した調整を必要とし,取引コストを増加させる可能性がある.調整幅とコストをバランスさせなければならない.
異なるパラメータの組み合わせをテストして,Stoch指標を最適化して,よりよい信号品質と戦略の効果を得ることができる.
他の指標のフィルター信号と組み合わせたり,調整幅を決定したりして,戦略の安定性を向上させるため,ストップ・ローズ・メカニズムを最適化することができる.
様々な追跡アルゴリズムを研究し,調整頻度を低減しながら,損失を防止する.
MT4/MT5との接続方法を最適化して,アラートをタイムリーに効率的に確保し,遅延問題を減らすことができます.
自動ストップモードと手動モードの切り替えが導入され,異なる市場条件によって異なるストップメカニズムが使用されます.
この戦略は,まず,ストック指数に基づいて買い売りのタイミングを判断し,その後,保有期間中に価格の変動をリアルタイムで追跡し,ストップ・ロスを調整し,アラート指令の自動化により調整情報を発信する.このダイナミック・ストップ・メカニズムは,市場の変化に応じてポジションリスクを主動的に管理し,人工的干渉を減らすことで効率性を高める.同時に,直感的なストップ・ロスの調整マークは,監視することも容易である.この戦略は,信号フィルタリングとストップ・ロスのアルゴリズムをさらに最適化して,利益の空間を向上させることができる.全体的に,ダイナミック・ストップ・トラッキング戦略は,多動的な市場を追跡し,ポジションのリスクを自動的に調整するのに適しています.
/*backtest
start: 2022-12-27 00:00:00
end: 2024-01-02 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="Moving Stop-Loss mechanism", overlay=true)
// This script was created for educational purposes only and it is a spin-off of my previous script:
// https://www.tradingview.com/script/9MJO3AgE-TradingView-Alerts-to-MT4-MT5-dynamic-variables-NON-REPAINTING/
// This spin-off adds very often requested Moving Stop-Loss Mechanism - the logic here moves the stop-loss each time
// a new pivot is detected.
//
// Last lines of the script include alert() function calls, with a syntax compatible with TradingConnector
// for execution in Forex/indices/commodities/crypto markets via MetaTrader.
// Please note that "tradeid=" variable must be passed with each alert, so that MetaTrader knows which
// trade to modify.
TakeProfitLevel=input(400)
// **** Entries logic, based on Stoch **** {
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)
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.red, title="stoploss_long")
plot(stoploss_short, color=color.lime, title="stoploss_short")
// Stop-Loss Updating mechanism
enable_stoploss_mechanism=input(true, title="Enable Stoploss Modification Mechanism")
UpdateLongStopLoss = strategy.position_size>0 and strategy.position_size[1]>0 and piv_low and pl!=stoploss_long and not GoLong and enable_stoploss_mechanism
UpdateShortStopLoss = strategy.position_size<0 and strategy.position_size[1]<0 and piv_high and ph!=stoploss_short and not GoShort and enable_stoploss_mechanism
if UpdateLongStopLoss
stoploss_long := pl
if UpdateShortStopLoss
stoploss_short := ph
plotshape(UpdateLongStopLoss ? stoploss_long[1]-300*syminfo.mintick : na, location=location.absolute, style=shape.labelup, color=color.lime, textcolor=color.white, text="SL\nmove")
plotshape(UpdateShortStopLoss ? stoploss_short[1]+300*syminfo.mintick : na, location=location.absolute, style=shape.labeldown, color=color.red, textcolor=color.black, text="SL\nmove")
// } End of Pivot-points and stop-loss logic
// **** Trade counter **** {
var int trade_id=0
if GoLong or GoShort
trade_id:=trade_id+1
// } End of Trade counter
strategy.entry("Long", strategy.long, when=GoLong)
strategy.exit("XLong", from_entry="Long", stop=stoploss_long, profit=TakeProfitLevel)
strategy.entry("Short", strategy.short, when=GoShort)
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 UpdateLongStopLoss
alertsyntax_updatelongstoploss='slmod slprice=' + tostring(stoploss_long) + ' tradeid=' + tostring(trade_id)
alert(message=alertsyntax_updatelongstoploss, freq=alert.freq_once_per_bar_close)
if UpdateShortStopLoss
alertsyntax_updateshortstoploss='slmod slprice=' + tostring(stoploss_short) + ' tradeid=' + tostring(trade_id)
alert(message=alertsyntax_updateshortstoploss, freq=alert.freq_once_per_bar_close)