
これは,一目均衡移動平均に基づくトレンド追跡戦略である. これは,均線,川Fusion一目均衡移動平均と精密な入場出場メカニズムを融合し,率を向上させることを目的としている.
この戦略は,主に最後の取引日の閉盘価格とユーザー定義の入力パラメータを計算して,一目均衡の移動平均を構築する.価格が上昇すると平均線を突破すると,多めに;価格が低下すると平均線を突破すると,空いて.そして,条件が達成されたときに,ストップ・ロズ・ストップ・価格を設定する.
同時に,この戦略は,一目均衡移動平均の色を判定する雲確認機構を追加した. 一目均衡移動平均の色が緑である場合にのみ多めにし,色が赤である場合にのみ空にする.これは,部分的に不正確な信号をフィルタリングして,戦略の利益の確率を向上させる.
この戦略の最大の利点は,平均線と一目均衡移動平均の2つの指標の利点を組み合わせることであり,価格平均の全体的な動きを考慮するとともに,最後の取引日の閉盘価格の分数変化にも注目している.さらに,クラウド確認機構は,取引の偽信号を回避し,戦略の安定性を高めます.
パラメータ最適化に関しては,ストップ・ストップの設定も,この戦略のリスクを制御できるようにする.最後に,一目均衡移動平均は,より新しい技術指標として,多くの人にはまだ馴染みのないものであり,この戦略の適用に先発的な優位性をもたらしている.
この戦略の最大のリスクは,一見均衡移動平均の自体の不安定性にある.新しい指標として,その長期的有効性とパラメータ最適化スペースは議論の余地がある.モデルが失敗すると仮定すれば,大量の誤信号が生成されるだろう.
さらに,トレンドを追跡する戦略は,トレンドの逆転の危険にさらされます. 価格が平均線を突破してすぐに調節されると,この戦略は大きな損失を被ります.
この戦略は,以下の方法でさらに最適化できます.
一見均衡移動平均の length 参数を最適化して,最適な均衡点を見つけます.
異なるストップパラメータの設定をテストし,最適なパラメータの組み合わせを決定する. ストップ幅が大きすぎると利益上限が制限され,ストップ幅が小さすぎるとリスクが大きすぎます.
MACD,KDなどの他の技術指標の判断を追加し,多指標のコンセンサスを形成し,誤った信号をさらに回避します.
異なる品種,周期を回測し,最適な戦略の適用シナリオを決定する.
マシン・ラーニング・モデルの導入を考慮し,パラメータの動的最適化と戦略の自主調整を実現する.
この戦略は,均線と一目平衡移動平均の優位性を統合し,合理的なストップ・ロスを設定し,クラウド確認機構を追加し,トレンドを効果的に追跡し,リスクを制御します.この戦略は,株式指数,外貨,商品および暗号通貨などの品種に広く適用され,推奨される定量化戦略です.
/*backtest
start: 2022-11-17 00:00:00
end: 2023-11-23 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
strategy("Ichimoku Backtester with TP and SL", overlay=true,
currency = currency.USD, default_qty_type = strategy.percent_of_equity,
default_qty_value = 95)
//@version=4
//Inputs
ts_bars = input(9, minval=1, title="Tenkan-Sen Bars")
ks_bars = input(26, minval=1, title="Kijun-Sen Bars")
ssb_bars = input(52, minval=1, title="Senkou-Span B Bars")
cs_offset = input(26, minval=1, title="Chikou-Span Offset")
ss_offset = input(26, minval=1, title="Senkou-Span Offset")
long_entry = input(true, title="Long Entry")
short_entry = input(true, title="Short Entry")
wait_for_cloud = input(true, title="Wait for Cloud Confirmation")
use_short_stop_loss = input(true, title="Use Short Stop Loss")
short_stop_loss = input(title="Short Stop Loss (%)", type=input.float, minval=0.0, step=0.1,
defval=5) * 0.01
use_long_stop_loss = input(true, title="Use Long Stop Loss")
long_stop_loss = input(title="Long Stop Loss (%)", type=input.float, minval=0.0, step=0.1,
defval=5) * 0.01
use_short_take_profit = input(true, title="Use Short Take Profit")
short_take_profit = input(title="Short Take Profit (%)", type=input.float, minval=0.0, step=0.1,
defval = 20) * .01
use_long_take_profit = input(true, title="Use Long Take Profit")
long_take_profit = input(title="Long Take Profit (%)", type=input.float, minval=0.0, step=0.1,
defval = 20) * .01
// === INPUT SHOW PLOT ===
showDate = input(defval = false, title = "Show Date Range", type = input.bool)
// === INPUT BACKTEST RANGE ===
fromMonth = input(defval = 1, title = "From Month", type = input.integer, minval = 1, maxval = 12)
fromDay = input(defval = 1, title = "From Day", type = input.integer, minval = 1, maxval = 31)
fromYear = input(defval = 2020, title = "From Year", type = input.integer, minval = 1970)
thruMonth = input(defval = 1, title = "Thru Month", type = input.integer, minval = 1, maxval = 12)
thruDay = input(defval = 1, title = "Thru Day", type = input.integer, minval = 1, maxval = 31)
thruYear = input(defval = 2112, title = "Thru Year", type = input.integer, minval = 1970)
// === FUNCTION EXAMPLE ===
start = timestamp(fromYear, fromMonth, fromDay, 00, 00) // backtest start window
finish = timestamp(thruYear, thruMonth, thruDay, 23, 59) // backtest finish window
window() => time >= start and time <= finish ? true : false // create function "within window of time"
middle(len) => avg(lowest(len), highest(len))
// Ichimoku Components
tenkan = middle(ts_bars)
kijun = middle(ks_bars)
senkouA = avg(tenkan, kijun)
senkouB = middle(ssb_bars)
bgcolor(color = showDate and window() ? color.gray : na, transp = 90) // plot within time window
// Plot Ichimoku Kinko Hyo
plot(tenkan, color=#0496ff, title="Tenkan-Sen")
plot(kijun, color=#991515, title="Kijun-Sen")
plot(close, offset=-cs_offset+1, color=#459915, title="Chikou-Span")
sa=plot(senkouA, offset=ss_offset-1, color=color.green, title="Senkou-Span A")
sb=plot(senkouB, offset=ss_offset-1, color=color.red, title="Senkou-Span B")
fill(sa, sb, color = senkouA > senkouB ? color.green : color.red, title="Cloud color")
ss_high = max(senkouA[ss_offset-1], senkouB[ss_offset-1])
ss_low = min(senkouA[ss_offset-1], senkouB[ss_offset-1])
// Entry/Exit Signals
tk_cross_bull = tenkan > kijun
tk_cross_bear = tenkan < kijun
cs_cross_bull = mom(close, cs_offset-1) > 0
cs_cross_bear = mom(close, cs_offset-1) < 0
price_above_kumo = close > ss_high
price_below_kumo = close < ss_low
senkou_green = senkouA > senkouB ? true : false
bullish = tk_cross_bull and cs_cross_bull and price_above_kumo
bearish = tk_cross_bear and cs_cross_bear and price_below_kumo
if (wait_for_cloud)
bullish := bullish and senkou_green
bearish := bearish and not senkou_green
longStopPrice = strategy.position_avg_price * (1 - long_stop_loss)
shortStopPrice = strategy.position_avg_price * (1 + short_stop_loss)
longLimitPrice = strategy.position_avg_price * (1 + long_take_profit)
shortLimitPrice = strategy.position_avg_price * (1 - short_take_profit)
in_long = false
in_long := in_long[1]
open_long = bullish and not in_long
open_short = bearish and in_long
if (open_long)
in_long := true
if (open_short)
in_long := false
strategy.entry("Long", strategy.long, when=open_long and long_entry and (showDate ? window() : true))
strategy.entry("Short", strategy.short ,when=open_short and short_entry and (showDate ? window() : true))
if (strategy.position_size > 0.0)
if (use_long_stop_loss and not use_long_take_profit)
strategy.exit("Long", stop = longStopPrice)
if (use_long_take_profit and not use_long_stop_loss)
strategy.exit("Long", limit = longLimitPrice)
if (use_long_take_profit and use_long_stop_loss)
strategy.exit("Long", stop = longStopPrice, limit=longLimitPrice)
if (strategy.position_size < 0.0)
if (use_short_stop_loss and not use_short_take_profit)
strategy.exit("Short", stop = shortStopPrice)
if (use_short_take_profit and not use_short_stop_loss)
strategy.exit("Short", limit = shortLimitPrice)
if (use_short_take_profit and use_short_stop_loss)
strategy.exit("Short", stop = shortStopPrice, limit = shortLimitPrice)
strategy.close("Long", when=bearish and not short_entry and (showDate ? window() : true))
strategy.close("Short", when=bullish and not long_entry and (showDate ? window() : true))