この戦略は,ウィリアムズ%R指標をベースにし,ダイナミックな取利益とストップロスのレベルを調整することで取引パフォーマンスを最適化します.ウィリアムズ%Rが過売りエリア (-80) を越えると買い信号が生成され,過買いエリア (-20) を越えると売れ信号が生成されます.指数関数移動平均 (EMA) がウィリアムズ%R値を滑らかにし,ノイズを減らすために使用されます.この戦略は,異なる市場条件とトレーダーの好みに適応するために,指標期間,取利益/ストップロスのレベル,取引時間,取引方向の選択を含む柔軟なパラメータ設定を提供しています.
ウィリアムズ %RダイナミックTP/SL調整戦略は,異なる市場環境と取引スタイルに適応するために柔軟なパラメータ設定を提供しながら,単純で効果的な方法で過剰購入および過剰販売価格条件を把握します.この戦略は,リスクをより適切に制御し,利益を保護できる,収益率とストップ損失レベルを動的に調整します.しかし,この戦略を実践する際には,パラメータ設定,信号確認,取引時間の選択などの要因に注意を払い,戦略の安定性と収益性をさらに向上させなければなりません.
/*backtest start: 2024-05-01 00:00:00 end: 2024-05-31 23:59:59 period: 4h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Williams %R Strategy defined buy/sell criteria with TP / SL", overlay=true) // User inputs for TP and SL levels tp_level = input.int(defval=60, title="Take Profit (ticks)", minval=10, maxval=500, step=10) sl_level = input.int(defval=60, title="Stop Loss (ticks)", minval=10, maxval=200, step=10) // Williams %R calculation length = input.int(defval=21, title="Length", minval=5, maxval=50, step=1) willy = 100 * (close - ta.highest(length)) / (ta.highest(length) - ta.lowest(length)) // Exponential Moving Average (EMA) of Williams %R ema_length = input.int(defval=13, title="EMA Length", minval=5, maxval=50, step=1) ema_willy = ta.ema(willy, ema_length) // User inputs for Williams %R thresholds buy_threshold = -80 sell_threshold = -20 // User input to enable/disable specific trading hours use_specific_hours = input.bool(defval=false, title="Use Specific Trading Hours") start_hour = input(defval=timestamp("0000-01-01 09:00:00"), title="Start Hour") end_hour = input(defval=timestamp("0000-01-01 11:00:00"), title="End Hour") // User input to choose trade direction trade_direction = input.string(defval="Both", title="Trade Direction", options=["Buy Only", "Sell Only", "Both"]) // User input to enable/disable "Minutes Before" and "Minutes After" options enable_minutes_before_after = input.bool(defval=true, title="Enable Minutes Before/After Options") minutes_before = enable_minutes_before_after ? input.int(defval=10, title="Minutes Before the Top of the Hour", minval=0, maxval=59, step=1) : 0 minutes_after = enable_minutes_before_after ? input.int(defval=10, title="Minutes After the Top of the Hour", minval=0, maxval=59, step=1) : 0 // Condition to check if the current minute is within the user-defined time window around the top of the hour is_top_of_hour_range = (minute(time) >= (60 - minutes_before) and minute(time) <= 59) or (minute(time) >= 0 and minute(time) <= minutes_after) // Condition to check if the current time is within the user-defined specific trading hours in_specific_hours = true if use_specific_hours in_specific_hours := (hour(time) * 60 + minute(time)) >= (hour(start_hour) * 60 + minute(start_hour)) and (hour(time) * 60 + minute(time)) <= (hour(end_hour) * 60 + minute(end_hour)) // Buy and Sell conditions with time-based restriction buy_condition = ta.crossover(willy, buy_threshold) and is_top_of_hour_range and in_specific_hours sell_condition = ta.crossunder(willy, sell_threshold) and is_top_of_hour_range and in_specific_hours // Strategy entry and exit with TP and SL if (trade_direction == "Buy Only" or trade_direction == "Both") and buy_condition strategy.entry("Buy", strategy.long) if (trade_direction == "Sell Only" or trade_direction == "Both") and sell_condition strategy.entry("Sell", strategy.short) // If a buy entry was taken, allow the trade to be closed after reaching TP and SL or if conditions for a sell entry are true if (strategy.opentrades > 0) strategy.exit("TP/SL", profit=tp_level, loss=sl_level) // Plot Williams %R and thresholds for visualization hline(-20, "Upper Band", color=color.red) hline(-80, "Lower Band", color=color.green) plot(willy, title="%R", color=color.yellow, linewidth=2) plot(ema_willy, title="EMA", color=color.aqua, linewidth=2)